VAULT-43873 return 431 for oversized token headers#31980
Closed
jorge-aquino wants to merge 1 commit into
Closed
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Author
|
Closing this PR because it was opened against the CE repo. l'll reopen the change in vault-enterprise. |
|
CI Results: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What does this PR do?
Summary
Updates Vault’s token header size validation to return
431 Request Header Fields Too Largeinstead of400 Bad Requestwhen authentication token headers exceed the configured size limit.This applies to oversized
X-Vault-Tokenheaders and oversizedAuthorization: Bearertoken values.Test-first confirmation
I followed the bug test-first workflow for this change. I first ran the focused token-header test with the existing implementation and confirmed it passed with the old
400 Bad Requestexpectation.I then changed the focused oversized-token test expectation from
http.StatusBadRequesttohttp.StatusRequestHeaderFieldsTooLargeand reran the test. It failed withexpected: 431andactual: 400, confirming the implementation still returned the old status code before the fix.Implementation
After confirming the test failed for the expected reason, I updated
wrapTokenHeaderSizeHandlerinhttp/util.goso oversized authentication token headers returnhttp.StatusRequestHeaderFieldsTooLarge.Both oversized token paths were updated:
X-Vault-TokenAuthorization: BearerTest updates
After the implementation change, the focused oversized-token test passed. I then ran the broader token-header test group, which exposed other assertions still expecting
400for the same oversized token/header validation path.I updated only the related assertions that exercise oversized token/header validation, including the custom limit case, multiple authorization header case, error response format case, and the API listener enforcement case. The cluster listener skip behavior remains unchanged.
Testing
go test ./http -run TestTokenHeader_ExceedsDefaultLimit_IsRejected -vgo test ./http -run TokenHeader -v -count=1go test ./http -count=1All passed.
TODO only if you're a HashiCorp employee
backport/label that matches the desired release branch.PCI review checklist
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.