Skip to content

Commit 6704800

Browse files
refactor(errors): improve generic error template and remove unsafe exception message output
1 parent 6549e85 commit 6704800

2 files changed

Lines changed: 31 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to this package are documented in this file.
44

5+
## [1.1.0] — 2025-11-16
6+
7+
### Changed
8+
9+
- Improved the generic error template: now only the standard, safe error message corresponding to the HTTP code is displayed.
10+
- Removed the display of raw exception messages in page headers (title and h2) to improve security.
11+
- Consistent message generation style: strict matching of the HTTP code with predefined text is used.
12+
- Updated the footer in the template (Codemonster Errors).
13+
514
## [1.0.0] — 2025-11-10
615

716
### Added

resources/views/errors/generic.php

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1+
<?php
2+
$defaultMessages = [
3+
400 => 'Bad Request',
4+
401 => 'Unauthorized',
5+
403 => 'Forbidden',
6+
404 => 'Not Found',
7+
405 => 'Method Not Allowed',
8+
408 => 'Request Timeout',
9+
422 => 'Unprocessable Entity',
10+
429 => 'Too Many Requests',
11+
500 => 'Internal Server Error',
12+
502 => 'Bad Gateway',
13+
503 => 'Service Unavailable',
14+
504 => 'Gateway Timeout',
15+
];
16+
17+
$code = $status ?? 500;
18+
$messageText = $defaultMessages[$code] ?? 'An unexpected error occurred';
19+
?>
20+
121
<!DOCTYPE html>
222
<html lang="en">
323

424
<head>
525
<meta charset="UTF-8">
626
<title>
727
<?= htmlspecialchars($status) ?>
8-
<?= htmlspecialchars($message ?: 'An unexpected error occurred') ?>
28+
<?= htmlspecialchars($messageText) ?>
929
</title>
1030
<style>
1131
:root {
@@ -34,40 +54,33 @@
3454
font-size: 52px;
3555
margin-bottom: 10px;
3656
color: #007bff;
37-
/* Codemonster blue */
3857
}
3958

4059
h2 {
4160
font-size: 22px;
4261
color: #334155;
43-
/* slate-700 */
4462
margin-bottom: 12px;
4563
}
4664

4765
p {
4866
color: #64748b;
49-
/* slate-500 */
5067
font-size: 16px;
5168
}
5269

5370
footer {
5471
margin-top: 24px;
5572
color: #94a3b8;
56-
/* slate-400 */
5773
font-size: 13px;
5874
}
5975

60-
/* 🌙 Dark theme */
6176
@media (prefers-color-scheme: dark) {
6277
body {
6378
background: #0a192f;
64-
/* deep navy blue */
6579
color: #e2e8f0;
6680
}
6781

6882
h1 {
6983
color: #339cff;
70-
/* lighter Codemonster blue */
7184
}
7285

7386
h2 {
@@ -86,32 +99,11 @@
8699
</head>
87100

88101
<body>
89-
<?php
90-
$defaultMessages = [
91-
400 => 'Bad Request',
92-
401 => 'Unauthorized',
93-
403 => 'Forbidden',
94-
404 => 'Not Found',
95-
405 => 'Method Not Allowed',
96-
408 => 'Request Timeout',
97-
422 => 'Unprocessable Entity',
98-
429 => 'Too Many Requests',
99-
500 => 'Internal Server Error',
100-
502 => 'Bad Gateway',
101-
503 => 'Service Unavailable',
102-
504 => 'Gateway Timeout',
103-
];
104-
105-
$code = $status ?? 500;
106-
$messageText = $message
107-
?: ($defaultMessages[$code] ?? 'An unexpected error occurred');
108-
?>
109-
110102
<div class="container">
111103
<h1><?= htmlspecialchars($code) ?></h1>
112104
<h2><?= htmlspecialchars($messageText) ?></h2>
113105
<p>Sorry, something went wrong while processing your request.</p>
114-
<footer>Codemonster Annabel</footer>
106+
<footer>Codemonster Errors</footer>
115107
</div>
116108
</body>
117109

0 commit comments

Comments
 (0)