Skip to content

Require a space after the Basic authentication scheme - #3138

Merged
vishr merged 1 commit into
labstack:masterfrom
Shubham-Padkonde:fix/basic-auth-scheme-boundary
Oct 22, 2026
Merged

vishr merged 1 commit into
labstack:masterfrom
Shubham-Padkonde:fix/basic-auth-scheme-boundary

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown
Contributor

BasicAuth checks the Basic prefix but does not check the following separator. As a result, BasicX followed by valid encoded credentials reaches the protected handler. An unrelated scheme with that prefix can also consume AllowedCheckLimit, preventing a later valid Basic header from being checked.

Require the space after the scheme before decoding or counting a header. Case-insensitive Basic matching and the existing invalid-base64 behavior are unchanged.

Both added regression cases fail before the fix. The complete Linux go test -race ./... suite and go vet ./... pass afterward.

@vishr vishr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the minimal scheme-boundary check and regression cases. The length check makes the separator access safe; case-insensitive Basic matching is preserved. This fixes parsing and check-limit accounting; valid credentials are still required.

@vishr
vishr merged commit 0996992 into labstack:master Oct 22, 2026
@vishr

vishr commented Oct 22, 2026

Copy link
Copy Markdown
Member

Merged with contributor credit. The v4 backport is open at #3188, with a v4-specific regression that rejects BasicX without calling the credential validator. Local race tests and vet pass.

vishr added a commit that referenced this pull request Oct 22, 2026
Backport #3138. Reject malformed schemes such as BasicX before decoding
credentials or invoking the validator. v4 reads only its first Authorization
header and has no AllowedCheckLimit, so its regression covers that API.

Co-authored-by: Shubham Padkonde <[email protected]>
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.

2 participants