Skip to content

fix(cas-auth): return 400 instead of 500 for SLO POST with empty body#13471

Merged
nic-6443 merged 2 commits into
apache:masterfrom
nic-6443:fix/cas-auth-empty-body-1639
Jun 4, 2026
Merged

fix(cas-auth): return 400 instead of 500 for SLO POST with empty body#13471
nic-6443 merged 2 commits into
apache:masterfrom
nic-6443:fix/cas-auth-empty-body-1639

Conversation

@nic-6443

@nic-6443 nic-6443 commented Jun 4, 2026

Copy link
Copy Markdown
Member

A POST to the CAS callback path with an empty request body returns a 500 instead of a clean 400.

The single-logout branch in cas-auth's access reads the body and immediately calls :match on it:

local data = core.request.get_body()
local ticket = data:match("<samlp:SessionIndex>(.*)</samlp:SessionIndex>")

core.request.get_body() returns nil when there's no body, so data:match raises attempt to index local 'data' (a nil value) and the request 500s — even though the very next line already handles the "no ticket" case with a 400, it's never reached.

Fix is a one-liner: guard the body before matching so a missing/empty body falls through to the existing 400 branch. A normal CAS ticket callback (a GET with ?ticket=) is unaffected.

Added a test that POSTs to the callback with no body and asserts a 400 — it fails with 500 before the fix.

Copilot AI review requested due to automatic review settings June 4, 2026 01:34
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jun 4, 2026

Copilot AI 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.

Pull request overview

This PR fixes a nil-body handling bug in the cas-auth plugin’s single-logout (SLO) POST callback path so malformed logout requests with an empty body return a clean 400 instead of triggering a Lua runtime error and returning 500.

Changes:

  • Guard the SLO POST body before calling :match to avoid indexing a nil value.
  • Add a regression test that POSTs to the CAS callback endpoint with no body and asserts a 400 response.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apisix/plugins/cas-auth.lua Prevents nil:match(...) in SLO POST handling so empty-body requests return 400.
t/plugin/cas-auth.t Adds a regression test ensuring empty-body SLO POST requests return 400 (not 500).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apisix/plugins/cas-auth.lua
An empty <samlp:SessionIndex></samlp:SessionIndex> matched the empty
string under (.*), passing an empty ticket through instead of returning
400. Require a non-empty SessionIndex with (.+).
@nic-6443
nic-6443 merged commit 6d320c0 into apache:master Jun 4, 2026
28 of 30 checks passed
@nic-6443
nic-6443 deleted the fix/cas-auth-empty-body-1639 branch June 4, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants