Skip to content

Fix preaccess phase ngx ok skips limiter - #62

Merged
kjdev merged 4 commits into
mainfrom
fix/preaccess-phase-ngx-ok-skips-limiter
Jul 14, 2026
Merged

kjdev merged 4 commits into
mainfrom
fix/preaccess-phase-ngx-ok-skips-limiter

Conversation

@kjdev

@kjdev kjdev commented Jul 13, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue in the PREACCESS phase where successful JWT authentication could skip subsequent handlers.
    • Ensured JWT claims are still available for downstream controls, including request rate limiting.
    • Kept authentication enforcement and failure response behavior unchanged.
  • Documentation
    • Updated auth_jwt_phase documentation to reflect correct PREACCESS continuation, subrequest limitations, and auth_delay behavior.
  • Tests
    • Added a new PREACCESS-focused test verifying $jwt_claim_* is populated before rate limiting runs.

kjdev added 2 commits July 13, 2026 11:39
ngx_http_auth_jwt_http_ok() always returned NGX_OK regardless of
phase. nginx's generic phase checker used for PREACCESS advances to
the next phase entirely on NGX_OK, so with auth_jwt_phase preaccess a
successful request skipped every other PREACCESS handler registered
after this module, including limit_req/limit_conn and third-party
modules keying on the claim variables this module populates (e.g.
nginx-ratelimit on $jwt_claim_sub). Return NGX_DECLINED when
phase == NGX_HTTP_PREACCESS_PHASE so the phase continues to the next
handler instead, matching the convention used by realip and other
variable-populating PREACCESS handlers. Access-phase behavior and
failure handling are unchanged.
Add a regression test that runs auth_jwt in preaccess mode with
limit_req_zone keyed on $jwt_claim_sub. Two pipelined requests with
the same sub over one connection expect 200 then 503, proving
limit_req actually executes after this module in the same PREACCESS
phase instead of being skipped.
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eaf8b8f9-5999-4d68-99fe-b75395343920

📥 Commits

Reviewing files that changed from the base of the PR and between 20702db and e8eb240.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • docs/DIRECTIVES.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • docs/DIRECTIVES.md

📝 Walkthrough

Walkthrough

The JWT module now returns NGX_DECLINED after successful preaccess authentication, allowing subsequent PREACCESS handlers to run. Documentation, changelog notes, and a limit_req integration test describe and verify the behavior.

Changes

PREACCESS authentication flow

Layer / File(s) Summary
PREACCESS return behavior and validation
src/ngx_http_auth_jwt_module.c, t/auth_jwt_phase_limit_req.t, docs/DIRECTIVES.md, CHANGELOG.md
Successful PREACCESS authentication returns NGX_DECLINED, allowing limit_req to use $jwt_claim_sub; documentation and changelog entries describe the phase behavior and ACCESS-phase constraints.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant JWTModule
  participant NginxPreaccess
  participant LimitReq
  JWTModule->>NginxPreaccess: Authenticate and resolve $jwt_claim_sub
  JWTModule-->>NginxPreaccess: Return NGX_DECLINED
  NginxPreaccess->>LimitReq: Continue PREACCESS processing
  LimitReq->>LimitReq: Apply request limit by JWT subject
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: fixing PREACCESS handlers so NGX_OK no longer skips subsequent limiters.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/preaccess-phase-ngx-ok-skips-limiter

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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 `@docs/DIRECTIVES.md`:
- Around line 186-187: Update the adjacent ACCESS-phase notes in the
documentation block so the blockquote remains continuous: remove the blank line
between the quoted lines or prefix that blank line with `>`, while preserving
the note text.
🪄 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: e7bf1295-9a82-4c7f-b518-91df0391e62e

📥 Commits

Reviewing files that changed from the base of the PR and between ab9d9c1 and 20702db.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • docs/DIRECTIVES.md
  • src/ngx_http_auth_jwt_module.c
  • t/auth_jwt_phase_limit_req.t

Comment thread docs/DIRECTIVES.md Outdated
kjdev added 2 commits July 13, 2026 11:48
…y gap

Explain that auth_jwt_phase preaccess now lets the phase continue
after a successful match so limit_req/limit_conn/nginx-ratelimit can
key on the resolved claim variables, and note the pre-existing
limitation that nginx core's auth_delay does not apply to 401
responses in the PREACCESS phase.
@kjdev
kjdev force-pushed the fix/preaccess-phase-ngx-ok-skips-limiter branch from 20702db to e8eb240 Compare July 13, 2026 02:49
@kjdev

kjdev commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kjdev
kjdev merged commit e8eb240 into main Jul 14, 2026
9 checks passed
@kjdev
kjdev deleted the fix/preaccess-phase-ngx-ok-skips-limiter branch July 14, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant