Skip to content

Revert "fix: validate path parameters and prevent traversal/injection in REST transcoder" - #9165

Merged
danieljbruce merged 1 commit into
mainfrom
revert-9151-transcoding-path-traversal-fix
Aug 18, 2026
Merged

danieljbruce merged 1 commit into
mainfrom
revert-9151-transcoding-path-traversal-fix

Conversation

@danieljbruce

Copy link
Copy Markdown
Contributor

Reverts #9151 to revert changes in the generated libraries in order to get a clean librarian build.

@danieljbruce
danieljbruce requested a review from a team as a code owner August 18, 2026 18:36
@github-actions
github-actions Bot requested a review from westarle August 18, 2026 18:36

@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 removes URI path validation logic and reverts the URL encoding functions (encodeWithSlashes and encodeWithoutSlashes) to a character-by-character split and map implementation, while also deleting associated unit tests. Feedback on this PR highlights a critical issue with this change: splitting strings character-by-character using .split('') splits Unicode surrogate pairs (such as emojis) into unpaired halves, which will cause encodeURIComponent to throw a URIError: URI malformed at runtime. It is recommended to restore the previous robust implementation that safely handles surrogate pairs.

Comment on lines 151 to 163
export function encodeWithSlashes(str: string): string {
return encodeURIComponent(str).replace(
/[!'()*]/g, // Characters preserved by encodeURIComponent
character => '%' + character.charCodeAt(0).toString(16).toUpperCase()
);
return str
.split('')
.map(c => (c.match(/[-_.~0-9a-zA-Z]/) ? c : encodeURIComponent(c)))
.join('');
}

/**
* Percent-encodes a string according to RFC 3986, preserving unreserved
* characters (alpha-numeric, '-', '_', '.', and '~') and slashes ('/'). All other
* characters are percent-encoded.
*
* @param {string} str - The input string to encode.
* @returns {string} The percent-encoded string with slashes preserved.
*/
export function encodeWithoutSlashes(str: string): string {
return str.split('/').map(encodeWithSlashes).join('/');
return str
.split('')
.map(c => (c.match(/[-_.~0-9a-zA-Z/]/) ? c : encodeURIComponent(c)))
.join('');
}

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

Reverting these functions to use .split('') and mapping over individual characters with encodeURIComponent re-introduces a critical bug. When a string contains Unicode surrogate pairs (such as emojis or non-BMP characters), .split('') splits them into unpaired surrogate halves. Passing an unpaired surrogate to encodeURIComponent throws a URIError: URI malformed at runtime.

We should keep the robust, standard-compliant implementation that uses encodeURIComponent on the whole string and then replaces the preserved characters, which safely handles surrogate pairs.

export function encodeWithSlashes(str: string): string {
  return encodeURIComponent(str).replace(
    /[!'()*]/g,
    character => '%' + character.charCodeAt(0).toString(16).toUpperCase()
  );
}

export function encodeWithoutSlashes(str: string): string {
  return str.split('/').map(encodeWithSlashes).join('/');
}

@danieljbruce danieljbruce Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's fine. We are going to reintroduce these changes again to solve the vulnerability.

@danieljbruce
danieljbruce enabled auto-merge (squash) August 18, 2026 18:43
@danieljbruce
danieljbruce merged commit b4b8635 into main Aug 18, 2026
44 checks passed
@danieljbruce
danieljbruce deleted the revert-9151-transcoding-path-traversal-fix branch August 18, 2026 19:00
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