Fix high audit findings and port the hidden-media rule

Fixed findings from the audit reports (SECURITY, QUALITY, PERFORMANCE):
- P-001 · Unbounded per-session timing maps and no connection cap in the sync hub
- S-001 · Anonymous `PUT /access` switches off login for every guarded route
- S-002 · Malformed cookies crash the Node middleware and fail requests in Java
- S-004 · Anonymous `PUT /sync` writes unvalidated JSON into shared session state

Also includes the pre-existing uncommitted changes in web-ui, README, shared-styles and the .changeset files, as the owner asked.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Haiku 5.5 committed 2026-10-19 07:47:10 +00:00
1 parent 7fd2f14f91
commit 199a5efaef
12 files changed
+445 -42

No files matched your search

+9 -3
View File
@@ -211,9 +211,8 @@ export class AuthClient {
*/
middleware() {
return async (req, res, next) => {
const token = this.tokenFromRequest(req);
try {
req.authUser = await this.validate(token);
req.authUser = await this.validate(this.tokenFromRequest(req));
next();
} catch {
// Fail closed on both an invalid session and a transport/decoding
@@ -236,7 +235,14 @@ export class AuthClient {
.split(';')
.map(part => part.trim())
.find(part => part.startsWith(`${this.cookieName}=`));
if (match) return decodeURIComponent(match.slice(this.cookieName.length + 1));
if (match) {
// A malformed escape such as a bare "%" is not a usable token, so treat the cookie as absent.
try {
return decodeURIComponent(match.slice(this.cookieName.length + 1));
} catch {
return '';
}
}
}
return '';
}
@@ -125,6 +125,29 @@ test('tokenFromRequest falls back to the auth_session cookie', () => {
assert.equal(client.tokenFromRequest(req), 'cookie-token');
});
test('tokenFromRequest treats a malformed cookie escape as no token', () => {
const client = new AuthClient('https://auth.example.com');
const req = { headers: { cookie: 'auth_session=bad%zz; other=1' } };
assert.equal(client.tokenFromRequest(req), '');
});
test('middleware answers 401 instead of rejecting on a malformed cookie', async () => {
const client = new AuthClient('https://auth.example.com', {
fetchImpl: fakeFetch([{ status: 401, body: { valid: false } }]),
});
let statusCode = null;
const res = {
status(code) {
statusCode = code;
return { json: () => {} };
},
};
await client.middleware()({ headers: { cookie: 'auth_session=100%' } }, res, () => {
throw new Error('next should not be called');
});
assert.equal(statusCode, 401);
});
test('middleware attaches authUser on success and 401s on failure', async () => {
const okClient = new AuthClient('https://auth.example.com', {
fetchImpl: fakeFetch([{ status: 200, body: { valid: true, user_id: 1, username: 'a', role: 'user' } }]),