api7 / api7/lua-resty-saml

login_callback ignores sess:save() failure, redirecting a user who got no session

Open
#52 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Perl
Stars
2
Forks
3
Avg merge
2d 20h
Merged PRs (30d)
3

Description

What

Both login and login_callback call sess:save() and ignore its result. resty.session's save returns nil, err on real failure paths: key derivation, encryption, MAC, cookie encoding, storage.

In login_callback the failure is silent and the consequence compounds: the code logs "login finish" and redirects as though the login succeeded, but no cookie was set, so the user arrives at the application unauthenticated and the application starts a new login. A deterministic failure, an oversized session built from large IdP attribute statements for instance, turns that into an infinite redirect loop through the IdP with nothing in the logs.

With replay_dict configured (#50), each lap also spends that lap's assertion, which contradicts the rule #50 settled: an assertion is spent only where it actually authenticates somebody. The replay angle itself is minor, since the browser follows the redirect and no longer holds the response to re-present.

In login the same ignored save means the callback later answers 503 for want of saml_state, a dead end rather than a loop.

What it should do
  • login_callback: check sess:save(). On failure, delete the replay keys spent for this response (spend_assertions returning its key list makes that small), log the error, and exit 500. An honest failure instead of a silent loop.
  • login: check sess:save() and fail the request with a logged error rather than redirecting to the IdP with state that was never kept.
Notes

Raised by Copilot reviewing #50. The ignored save predates #50 on both paths; #50 is only where the spent-assertion consequence was added.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace the login and login_callback paths where sess:save() is called, along with spend_assertions and the existing logging and error responses. Make save failures log an error, return 500, and in login_callback remove the replay keys spent for the response; verify both paths no longer redirect after an unsuccessful save.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
authentication, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.