Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,7 @@ Action: Updated the global error handler in `src/index.js` to explicitly interce
2026-04-30 — Avoid Modifying Express Router Internals in Tests
Learning: When writing isolated unit tests using `supertest`, attempting to mutate `app._router.stack` to dynamically inject routes before global error handlers fails because `app._router` is lazily initialized and can be undefined at module load time.
Action: Test error handlers by constructing an isolated `mockApp` using `express()` that mirrors the production routing logic rather than mutating the internals of the exported `app`.

2026-04-30 — Prevent X-Powered-By Header Leak on Unprotected Endpoints
Learning: When using Express, disabling the `x-powered-by` header using `app.disable('x-powered-by')` at the application level prevents the framework from automatically setting the header. Endpoints declared above global security middlewares like `helmet()` (which normally strips this header) will inadvertently leak this header if it is not explicitly disabled globally. Disabling it also saves a small amount of CPU overhead across all requests.
Action: Add `app.disable('x-powered-by')` near application initialization in `src/index.js` to guarantee the header is never generated, protecting routes that intentionally bypass global middleware for performance reasons.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ process.on('unhandledRejection', (reason, promise) => {
const app = express();
// Disable ETag generation for highly dynamic JSON APIs to save CPU cycles
app.set('etag', false);
app.disable('x-powered-by');

const HEALTH_RESPONSE = Buffer.from(JSON.stringify({ status: 'ok' }));
app.get('/health', (req, res) => {
Expand Down
1 change: 1 addition & 0 deletions tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test('GET /health returns 200', async () => {
const res = await request(app).get('/health');
assert.strictEqual(res.status, 200);
assert.deepStrictEqual(res.body, { status: 'ok' });
assert.strictEqual(res.headers['x-powered-by'], undefined);
});

test('POST /v1/chat/completions works with valid data', async () => {
Expand Down
1 change: 1 addition & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Module.prototype.require = function(name) {
post: () => mockApp,
get: () => mockApp,
set: () => mockApp,
disable: () => mockApp,
listen: (port, cb) => { if (cb) cb(); return mockApp; }
};
const expressMock = () => mockApp;
Expand Down
Loading