Repository navigation
Fix validate loc conf - #59
Conversation
ngx_http_auth_jwt_validate_requirement() cleared cf->validate.sig and cf->validate.exp on the shared per-worker loc_conf when a matching alg or exp requirement was met. Because the loc_conf is treated as read-only during request processing, the cleared flags persisted to every later request on the worker until reload. With an alg requirement that allows both "none" and a signing algorithm (e.g. `alg in [RS256, none]`), a single alg=none token permanently set validate.sig to 0, after which forged RS256 tokens passed signature verification unchecked, bypassing authentication. Snapshot cf->validate.sig/exp into request-scoped ctx fields at the entry of ngx_http_auth_jwt_validate() and route the requirement relaxation and the builtin exp/sig checks through ctx, so the loc_conf is never mutated.
Add a regression test for the per-worker loc_conf relaxation bypass: a first request meeting an `alg in [HS256, none]` requirement with an alg=none token must not disable signature verification for a later forged HS256 token, and builtin exp validation must apply on every request.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughFixes an authentication bypass where ChangesAuthentication bypass fix: request-scoped validation flags
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
t/auth_jwt_require_loc_conf_persist.t (1)
42-70: ⚡ Quick winAdd an explicit exp-requirement persistence regression case.
This scenario validates builtin exp behavior, but it doesn’t exercise the historical mutation path where an
exprequirement relaxed validation state. Add a case withauth_jwt_require_claim exp ...followed by a second request to confirm relaxation never leaks across requests.Suggested test shape
+=== test: exp requirement relaxation does not persist across requests +--- http_config +include $TEST_NGINX_CONF_DIR/authorized_server.conf; +map $http_x_token $jwt { + "match" $test1_jwt; + "expired" $test1_invalid_exp_jwt; +} +--- config +include $TEST_NGINX_CONF_DIR/jwt.conf; +location / { + auth_jwt "" token=$jwt; + auth_jwt_key_file $TEST_NGINX_DATA_DIR/jwks.json; + auth_jwt_require_claim exp ge $jwt_nowtime; + include $TEST_NGINX_CONF_DIR/authorized_proxy.conf; +} +--- request eval +[ + "GET /", + "GET /" +] +--- more_headers eval +[ + "X-Token: match", + "X-Token: expired" +] +--- error_code eval +[ + 200, + 401 +]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@t/auth_jwt_require_loc_conf_persist.t` around lines 42 - 70, Add a new test case after the existing "builtin exp validation is applied on every request" test that explicitly validates the `auth_jwt_require_claim exp` requirement persistence across requests. The new test should include a location configuration with `auth_jwt_require_claim exp` followed by multiple request scenarios to confirm that any relaxation of validation state does not leak between requests. Use the same pattern as the current test with request eval arrays and corresponding error_code eval arrays to verify that the exp validation behavior remains consistent and isolated per request.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@CHANGELOG.md`:
- Line 7: In the CHANGELOG.md entry, replace the spelling "builtin" with the
standard hyphenated form "built-in" to maintain consistency with user-facing
documentation conventions. The word appears in the context of describing the
"builtin exp / sig checks" in the security fix description and should be changed
to "built-in exp / sig checks".
---
Nitpick comments:
In `@t/auth_jwt_require_loc_conf_persist.t`:
- Around line 42-70: Add a new test case after the existing "builtin exp
validation is applied on every request" test that explicitly validates the
`auth_jwt_require_claim exp` requirement persistence across requests. The new
test should include a location configuration with `auth_jwt_require_claim exp`
followed by multiple request scenarios to confirm that any relaxation of
validation state does not leak between requests. Use the same pattern as the
current test with request eval arrays and corresponding error_code eval arrays
to verify that the exp validation behavior remains consistent and isolated per
request.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 08c00da9-33ac-4fd6-9e61-10b4346e893e
📒 Files selected for processing (3)
CHANGELOG.mdsrc/ngx_http_auth_jwt_module.ct/auth_jwt_require_loc_conf_persist.t
a079941 to
658e30b
Compare
Summary by CodeRabbit
Security
Tests