Skip to content
Open
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
8 changes: 8 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,11 @@ Action: Test error handlers by constructing an isolated `mockApp` using `express
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.

## 2026-05-02 — Cache CORS Preflight Requests

Learning:
Browser clients making cross-origin requests trigger a preflight OPTIONS request before every actual request unless cached. Without setting the `Access-Control-Max-Age` header, the Express gateway spends unnecessary CPU processing these identical preflight requests, leading to increased latency and load.

Action:
Configured the `cors` middleware in `src/index.js` with `maxAge: 86400` (24 hours) to instruct browsers to cache preflight OPTIONS responses, significantly reducing redundant network traffic and backend processing for repeated requests from the same client.
12 changes: 12 additions & 0 deletions .jules/warden.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,15 @@ Observation / Pruned:
Assessed JULES/BOLT's optimization fixing X-Powered-By header leak on bypassed endpoints. By globally disabling the 'x-powered-by' header via app.disable('x-powered-by'), endpoints like /health that are defined before global security middlewares (helmet) are protected from leaking the framework identifier. The change successfully improves security while saving CPU overhead. Ran tests and verified robustness. Zero dead code identified.
Alignment / Deferred:
Appended release notes for the security fix. Version bumped to 1.1.29.

2026-05-02 — Assessment & Lifecycle
Observation / Pruned:
Assessed repository state following previous optimizations. Since no new functional or architectural changes were introduced by the prior agent run, no new release cut or version bump is warranted. Maintained semantic integrity by preserving the existing v1.1.29 state. Zero dead code identified and pruned.
Alignment / Deferred:
Release deferred. Repository state verified and stable.

2026-05-02 — Assessment & Lifecycle
Observation / Pruned:
Assessed JULES/BOLT's optimization caching CORS preflight requests via the `maxAge: 86400` option in `src/index.js`. This avoids redundant backend parsing and significantly cuts request latency for browser clients. Tests updated to verify the `Access-Control-Max-Age` header, all passing with improved throughput metrics. Zero dead code identified or pruned.
Alignment / Deferred:
Appended release notes. Version bumped to 1.1.30.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.1.30] - 2026-05-02
### Changed
* **[Performance]:** Added `maxAge: 86400` to CORS options to cache preflight OPTIONS requests for 24 hours, reducing latency and backend load for browser clients. Zero dead code pruned.

## [1.1.29] - 2026-05-01
### Changed
* **[Security & Performance]:** Fixed an issue where high-frequency endpoints bypassing global middlewares leaked the `X-Powered-By` framework identifier. Globally disabled the header during application initialization, successfully mitigating the leak and saving CPU overhead across all requests. Zero dead code was pruned.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "one-api",
"version": "1.1.29",
"version": "1.1.30",
"description": "One API to rule them all. Unified gateway for 20+ LLM providers. OpenAI-compatible, single binary, zero config.",
"main": "src/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ app.get('/health', (req, res) => {

app.use(helmet());

let corsOptions = { origin: '*' };
let corsOptions = { origin: '*', maxAge: 86400 };
if (process.env.ALLOWED_ORIGINS) {
const origins = process.env.ALLOWED_ORIGINS.split(',').map(o => o.trim()).filter(Boolean);
if (origins.includes('*')) {
Expand Down
3 changes: 3 additions & 0 deletions tests/cors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test('CORS defaults to * when ALLOWED_ORIGINS is not set', async () => {
.set('Origin', 'http://example.com');

assert.strictEqual(res.headers['access-control-allow-origin'], '*');
assert.strictEqual(res.headers['access-control-max-age'], '86400');
});

test('CORS restricts to specific origins when ALLOWED_ORIGINS is set', async () => {
Expand All @@ -24,6 +25,7 @@ test('CORS restricts to specific origins when ALLOWED_ORIGINS is set', async ()
.set('Origin', 'https://bar.com');

assert.strictEqual(res1.headers['access-control-allow-origin'], 'https://bar.com');
assert.strictEqual(res1.headers['access-control-max-age'], '86400');

const res2 = await request(app)
.options('/health')
Expand All @@ -42,4 +44,5 @@ test('CORS allows * when ALLOWED_ORIGINS contains *', async () => {
.set('Origin', 'http://hacker.com');

assert.strictEqual(res.headers['access-control-allow-origin'], '*');
assert.strictEqual(res.headers['access-control-max-age'], '86400');
});