Skip to content

fix: secure URL transcoding path traversal vulnerability in REST fallback - #9146

Draft
danieljbruce wants to merge 22 commits into
mainfrom
jules-transcoding-path-traversal-vuln-fix-6401005213542870442
Draft

fix: secure URL transcoding path traversal vulnerability in REST fallback#9146
danieljbruce wants to merge 22 commits into
mainfrom
jules-transcoding-path-traversal-vuln-fix-6401005213542870442

Conversation

@danieljbruce

Copy link
Copy Markdown
Contributor

This PR resolves a directory path traversal and parameter injection vulnerability in the google-gax REST/Fallback transcoding layer. It implements strict validation of '.' and '..' segments for single and double asterisk wildcards and enforces RFC-3986 compliant percent encoding. It also includes 10 rigorous, high-quality tests on the @google-cloud/dialogflow-cx package to demonstrate these security mitigations and type safety fixes in action, without adding any lock files.


PR created automatically by Jules for task 6401005213542870442 started by @danieljbruce

…back

To prevent directory traversal and reserved-character injection attacks in fallback HTTP/REST transport, this commit implements the strict transcoding validation guidelines:
1. Rejects single-asterisk (*) matches resolving exactly to '.' or '..' with error: 'Invalid value {value} for {propertyName}'.
2. Rejects double-asterisk (**) matches containing segments exactly '.' or '..' with error: 'Value for {propertyName} must not contain segments that are exactly . or ..'.
3. Percent-encodes all variable segments except unreserved [-__.~/0-9a-zA-Z], ensuring characters like '!', ''', '(', ')', and '*' are encoded.
4. Filters out null and undefined values in buildQueryStringComponents array serialization to prevent TypeErrors.
5. Guards optional unmatched groups in applyPattern.

Includes a rigorous suite of 10 tests using the google-cloud-dialogflow-cx library to verify these mitigations in action.

Co-authored-by: danieljbruce <8935272+danieljbruce@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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

Code Review

This pull request introduces path traversal validation and stricter percent-encoding (specifically for characters like !'()*) to the transcoding module in google-gax. It also updates query string building to handle null/undefined array elements safely and adds a test suite in the Dialogflow CX package. The reviewer feedback highlights that using a local link: dependency in package.json will break the package when published to npm, and warns against using fragile relative paths and dynamic require() statements in the test file. It is highly recommended to move these transcoding tests directly into the google-gax package to maintain clean decoupling.

Comment thread packages/google-cloud-dialogflow-cx/package.json Outdated
Comment on lines +21 to +22
const transcodingPath = path.resolve(__dirname, '../../node_modules/google-gax/build/src/transcoding.js');
const transcoding = require(transcodingPath);

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.

high

This code violates two general rules:

  1. It hardcodes a relative path to node_modules (../../node_modules/google-gax/...), which is fragile and can break across different environments or directory structures.
  2. It uses require() with a dynamically computed path variable (transcodingPath), which is incompatible with bundlers and static analysis tools.

To resolve this, please move these tests to the google-gax package (core/packages/gax/test/) where the transcoding module can be imported directly and cleanly without hacky path resolution.

References
  1. Avoid hardcoding relative paths to dependencies in node_modules. Instead, resolve the path dynamically using require.resolve and path.join to ensure robustness across different environments and directory structures.
  2. Do not use require() with a dynamically computed path variable. The path argument in require() must be a constant string literal to ensure compatibility with bundlers and runtime environments.

danieljbruce and others added 21 commits August 13, 2026 14:14
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…870442' of https://github.com/googleapis/google-cloud-node into jules-transcoding-path-traversal-vuln-fix-6401005213542870442
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.

1 participant