Проверка rehash, login DoS и общего rate limit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
# Credential storage and log non-disclosure
|
||||
|
||||
Date: 2026-11-27
|
||||
Stand: local Docker Desktop, compose project hla-lab7
|
||||
|
||||
Command:
|
||||
python tests/credential_storage.py --base-url https://localhost:8443 --ca-file secrets/pki/public-ca/ca.crt
|
||||
|
||||
Observed result:
|
||||
PASS: password and session token are stored only as hashes and are absent from API/LB logs.
|
||||
|
||||
What the check does:
|
||||
- creates one synthetic user and one session over verified HTTPS;
|
||||
- reads the user's password_hash and the session token_hash from
|
||||
PostgreSQL using the operator connection;
|
||||
- requires password_hash to start with the measured
|
||||
$argon2id$v=19$m=32768,t=2,p=1$ profile and to differ from the password;
|
||||
- requires token_hash to be exactly the SHA-256 of the issued token
|
||||
(64 hex characters / 32 bytes) and not the token itself;
|
||||
- scans the API and nginx logs for the synthetic password, the synthetic
|
||||
token, the stored password hash and the stored token hash;
|
||||
- fails if any of those values appear in the logs.
|
||||
|
||||
Related black-box check:
|
||||
tests/login_dos.py asserts that 401/429 bodies and headers do not contain
|
||||
the tested username, password, hash or token. Known and unknown usernames
|
||||
return the same 401 code and message.
|
||||
|
||||
The synthetic password and token exist only in process memory; this file
|
||||
contains no credential values.
|
||||
@@ -0,0 +1,62 @@
|
||||
# Measured login DoS budget and shared rate limit
|
||||
|
||||
Date: 2026-11-27
|
||||
Stand: local Docker Desktop, compose project hla-lab7, two API replicas
|
||||
(0.75 CPU / 768 MiB each), nginx HTTPS ingress, Redis 7.4 over mTLS.
|
||||
|
||||
Commands:
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\benchmark-argon2.ps1
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\measure-login-dos.ps1 -SourceBudget
|
||||
|
||||
Argon2id calibration (0.75 CPU / 768 MiB, 5 warmups, 21 samples, unique salt):
|
||||
32768 KiB, t=2, p=1:
|
||||
encode p50 100.182 ms, p95 134.817 ms
|
||||
verify p50 115.483 ms, p95 165.503 ms
|
||||
Previous run of the same script: encode p95 150.3 ms, verify p95 142.7 ms.
|
||||
|
||||
Observed login budget (black-box through nginx):
|
||||
Per username: 5 attempts / 60 s, shared by both replicas.
|
||||
- 5 concurrent failed logins returned 401 and were served by two
|
||||
distinct X-Instance-Id values.
|
||||
- The 6th attempt returned 429 rate_limited with Retry-After 58 s.
|
||||
- 5 concurrent Argon2 verifications: p50 1547.045 ms, p95 1662.582 ms.
|
||||
This is queueing on the 0.75-CPU limit, not a single-request latency.
|
||||
- The 429 response took 19.682 ms, i.e. it did not run Argon2.
|
||||
Per source: 100 attempts / 60 s, shared by both replicas.
|
||||
- After the 60 s window was allowed to expire, 100 failed logins with
|
||||
distinct usernames returned 401; both replicas were observed.
|
||||
- The 101st attempt returned 429 rate_limited with Retry-After 60 s.
|
||||
- Sequential 401 path: p50 287.473 ms, p95 490.411 ms (includes
|
||||
TLS, Redis, PostgreSQL and Argon2id).
|
||||
- The 429 response took 18.654 ms, i.e. it did not run Argon2.
|
||||
Known and unknown usernames:
|
||||
- Both returned 401 with code "unauthorized" and the same message.
|
||||
- Known-user request 510.424 ms; unknown-user request 309.891 ms in
|
||||
that run. The difference is not a stable user-existence oracle; both
|
||||
paths run one Argon2id verification (the unknown path uses the dummy
|
||||
hash).
|
||||
|
||||
Budget calculation using the p95 verify time:
|
||||
- Per username: 5 * 165.503 ms = 0.83 s of Argon2 CPU per 60 s window.
|
||||
- Per source: 100 * 165.503 ms = 16.55 s of Argon2 CPU per 60 s window,
|
||||
i.e. about 0.276 CPU averaged over the window on the 0.75-CPU API limit.
|
||||
- The limiter is a rate cap, not a concurrency cap: a simultaneous burst
|
||||
can still queue on the CPU limit, as the 5-way burst above shows.
|
||||
- A Redis outage fails closed (503), so the expensive path is not exposed.
|
||||
|
||||
Shared-state and key handling:
|
||||
- The fixed-window counters live in Redis under
|
||||
messenger:login:user:<sha256> and messenger:login:source:<sha256>.
|
||||
- The Lua script increments both counters and sets the TTL atomically.
|
||||
- Both API replicas use the same Redis keys, so the budget is global for
|
||||
the deployment, not per process.
|
||||
- Raw usernames and source addresses are not used as Redis key material.
|
||||
|
||||
Known limitation:
|
||||
- The source key currently uses request.getRemoteAddr(), which is the
|
||||
nginx/LB address. It is therefore a global source cap shared by all
|
||||
clients behind the LB, not a per-client cap. The per-username limit is
|
||||
the primary per-account control. A trusted-proxy client-address model
|
||||
remains the next step.
|
||||
|
||||
No passwords, session tokens or password hashes are included.
|
||||
@@ -0,0 +1,36 @@
|
||||
# Password rehash and shared login-rate-limit unit checks
|
||||
|
||||
Date: 2026-11-27
|
||||
Stand: Windows host, Gradle 9.7.1, Java 23 toolchain
|
||||
|
||||
Command:
|
||||
.\gradlew.bat test --tests com.example.mtusi_messenger.security.DatabaseAuthenticationProviderTest --tests com.example.mtusi_messenger.security.LoginRateLimiterTest --no-daemon --console=plain
|
||||
|
||||
Observed result:
|
||||
BUILD SUCCESSFUL
|
||||
DatabaseAuthenticationProviderTest: 5 tests, 0 failures, 0 errors
|
||||
LoginRateLimiterTest: 5 tests, 0 failures, 0 errors
|
||||
|
||||
DatabaseAuthenticationProviderTest proves:
|
||||
- a valid legacy Argon2id hash (19456 KiB, t=2, p=1) is replaced after a
|
||||
successful login by a hash with the measured runtime profile
|
||||
(32768 KiB, t=2, p=1);
|
||||
- the replacement uses the compare-and-swap contract
|
||||
replacePasswordHash(userId, expectedHash, newHash);
|
||||
- a wrong password, an unknown user and an already-current hash do not
|
||||
rewrite the stored hash;
|
||||
- an unknown user and a non-Argon2 stored value are checked against the
|
||||
dummy hash, not against attacker-controlled stored text;
|
||||
- authentication failures do not echo the password or the stored hash.
|
||||
|
||||
LoginRateLimiterTest proves:
|
||||
- two limiter instances (simulated replicas) share the same username and
|
||||
source budgets through the same Redis template;
|
||||
- username matching is case-insensitive;
|
||||
- Redis keys are SHA-256 digests and do not contain the raw username or
|
||||
source address;
|
||||
- a Redis outage fails closed with AuthenticationServiceException instead
|
||||
of allowing expensive password verification;
|
||||
- invalid limit/window configuration is rejected.
|
||||
|
||||
No passwords, session tokens or password hashes are printed by these tests.
|
||||
Reference in New Issue
Block a user