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:
1 parent
7fd2f14f91
commit
199a5efaef
12 files changed
+445
-42
No files matched your search
@@ -715,9 +715,13 @@ public final class AuthClient {
|
||||
if (candidate.startsWith(prefix)) {
|
||||
String value = candidate.substring(prefix.length());
|
||||
try {
|
||||
return URLDecoder.decode(value, StandardCharsets.UTF_8.name());
|
||||
// URLDecoder would turn a literal "+" into a space; escape it first so it survives, as in Node.
|
||||
return URLDecoder.decode(value.replace("+", "%2B"), StandardCharsets.UTF_8.name());
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
return value;
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// A malformed escape such as a bare "%" is not a usable token, so treat the cookie as absent.
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +218,34 @@ class AuthClientTest {
|
||||
assertEquals("right", token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractTokenKeepsALiteralPlusSignInTheCookieValue() {
|
||||
AuthClient client = new AuthClient("https://auth.example.com");
|
||||
|
||||
String token = client.extractToken(name -> null, "auth_session=ab+cd%2Bef");
|
||||
|
||||
assertEquals("ab+cd+ef", token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractTokenTreatsAMalformedCookieEscapeAsNoToken() {
|
||||
AuthClient client = new AuthClient("https://auth.example.com");
|
||||
|
||||
String token = client.extractToken(name -> null, "auth_session=bad%zz; other=1");
|
||||
|
||||
assertEquals("", token);
|
||||
}
|
||||
|
||||
@Test
|
||||
void middlewareFailsClosedOnAMalformedCookieInsteadOfThrowing() throws Exception {
|
||||
AuthClient client = new AuthClient("https://auth.example.com");
|
||||
|
||||
String result = client.middleware(name -> null, "auth_session=100%",
|
||||
user -> "authenticated", () -> "unauthorized");
|
||||
|
||||
assertEquals("unauthorized", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void middlewareFailsClosedAndDoesNotInvokeTheHandlerOnAnInvalidSession() throws Exception {
|
||||
server = fakeAuthGuard(401, "{\"valid\":false}");
|
||||
|
||||
Reference in new issue
Block a user