You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Learning: For highly dynamic JSON API responses containing large static structures, using full-object JSON.stringify() causes significant serialization overhead. Pre-stringifying the static parts and using template literal interpolation for the dynamic fields reduces serialization overhead and improves throughput.
159
159
Action: Pre-stringify large static mock structures during module initialization and assemble the final JSON dynamically using string interpolation instead of `JSON.stringify`.
160
+
161
+
## 2026-04-24 — Abstract Content-Type and Fix 404 XSS Risk
162
+
163
+
Learning:
164
+
Setting `res.setHeader('Content-Type', 'application/json; charset=utf-8')` individually in every route handler and error path creates redundant, duplicated code and leaves room for bugs if missed. Additionally, reflecting the requested `req.path` back in the JSON body of a 404 handler without sanitization creates a potential vector for Cross-Site Scripting (XSS) if the client misinterprets the Content-Type.
165
+
166
+
Action:
167
+
Extracted the `Content-Type` header assignment into a global middleware placed before all routes but after security middleware (helmet/cors) in `src/index.js`. Optimized the 404 handler to return a frozen, precomputed Buffer `ERROR_NOT_FOUND` rather than a dynamic string, and explicitly removed `req.path` from the body to mitigate XSS vulnerabilities and improve throughput.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,10 @@
2
2
3
3
All notable changes to this project will be documented in this file.
4
4
5
+
## [1.1.22] - 2026-04-24
6
+
### Changed
7
+
***[Performance & Security]:** Extracted duplicate Content-Type header assignments into a single global middleware, reducing repeated calls. Mitigated potential XSS risk in 404 handler by removing reflected `req.path` and optimized it by replacing dynamic serialization with a precomputed, static Buffer.
8
+
5
9
## [1.1.21] - 2026-04-22
6
10
### Changed
7
11
***[Performance]:** Pre-stringified static JSON mock structures to reduce serialization overhead during API responses. Zero dead code pruned.
0 commit comments