Skip to content

fix: Validate path parameters against path traversal and parameter injection - #3236

Open
quartzmo wants to merge 5 commits into
googleapis:mainfrom
quartzmo:rest-uri-fix
Open

fix: Validate path parameters against path traversal and parameter injection#3236
quartzmo wants to merge 5 commits into
googleapis:mainfrom
quartzmo:rest-uri-fix

Conversation

@quartzmo

@quartzmo quartzmo commented Aug 26, 2026

Copy link
Copy Markdown
Member

Validates discovery-based path parameters in the request builder before template expansion.

Rejects '?' and '#' in reserved path parameters (+ and #) as a primary control to prevent parameter injection (since reserved expansions bypass URL-escaping).

Rejects '.' and '..' segments in all path parameters to prevent path traversal. Added unit tests for validation.

b/529889305

…jection

Validates discovery-based path parameters in the request builder before
template expansion.

Rejects '?' and '#' in reserved path parameters (+ and #)
as a primary control to prevent parameter injection (since reserved expansions
bypass URL-escaping).

Rejects '.' and '..' segments in all path parameters
to prevent path traversal.
@quartzmo
quartzmo requested a review from a team as a code owner August 26, 2026 21:44

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces validation for path parameters in RequestBuilder to prevent path traversal exploits and query/fragment injections, along with corresponding unit tests. A critical security issue was identified in the path traversal validation logic: splitting the parameter value by '/' before unescaping allows a bypass (e.g., '..%2f..' is not split, but unescapes to '../..'). It is recommended to unescape the entire parameter value first before splitting it into segments.

Comment thread Src/Support/Google.Apis.Core/Requests/RequestBuilder.cs Outdated

@efevans efevans left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as the in the gapic library, I'd prefer if we could ignore my initial request, and move back to string.split in this case to keep the implementation simpler and somewhat at parity with the gapic. I think it's harder to justify in this case since this is all new code whereas the gapic was changing a method that was already splitting, but I think it should be okay given the KTLO-stance towards discovery libs.

}
// Unescape the entire value first to prevent bypasses using URL-encoded slashes (e.g. %2f).
string unescapedVal = Uri.UnescapeDataString(val);
bool isReserved = op == "+" || op == "#";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the ruby implementation implementation here there's a check on non-reserved parameters for slashes, do we need that here?

@amanda-tarafa
amanda-tarafa self-requested a review August 29, 2026 18:17
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