Repository navigation
fix: add timeout and size limit to SAML metadata fetch - #2885
Open
Dextheking1 wants to merge 3 commits into
Open
Dextheking1 wants to merge 3 commits into
Dextheking1 wants to merge 3 commits into
Conversation
hf
requested changes
Oct 30, 2026
Comment on lines
+204
to
+208
| client := &http.Client{ | ||
| Timeout: samlMetadataFetchTimeout, | ||
| } | ||
|
|
||
| resp, err := client.Do(req) |
Contributor
There was a problem hiding this comment.
This should use a timeout context, not a new client.
| } | ||
|
|
||
| data, err := io.ReadAll(resp.Body) | ||
| data, err := io.ReadAll(io.LimitReader(resp.Body, maxSAMLMetadataSize+1)) |
Contributor
There was a problem hiding this comment.
If the data is compressed (usually is) this protects from nothing. There's a better way, reading the Content-Length and rejecting first, then using a LimitReader and rejecting if Content-Length doesn't match (illegal HTTP).
Author
|
done both. timeout now comes from a context on the request with DefaultClient, no separate client. size check now rejects on Content-Length first, then LimitReader on the decoded body, then rejects if the read length does not match Content-Length. gzip responses skip the length match since the transport decompresses them. added a gzip test, the four fetch tests pass locally. |
This branch has not been deployed
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.
fetchSAMLMetadata used http.DefaultClient and io.ReadAll with no bounds. A metadata_url that serves a huge body, or one that never finishes responding, ties up the fetch until the remote side gives up and reads unbounded memory. This also runs on the ACS path when cached metadata goes stale, so it does not need an admin call to trigger, just a provider whose metadata endpoint misbehaves.
Fix: dedicated client with a 10s timeout (same as OIDC discovery fetches) and a 5 MiB cap on the response body with an explicit error past the cap. Real single-IdP metadata is far below the cap.
Tests: new internal tests in ssoadmin_fetch_test.go cover the happy path, an oversized body, and a server that never responds.