fix(validate): reject dangerous Unicode characters in input validation#484
fix(validate): reject dangerous Unicode characters in input validation#484abhiram304 wants to merge 3 commits intogoogleworkspace:mainfrom
Conversation
🦋 Changeset detectedLatest commit: f6b959b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the security and robustness of input validation by extending checks to cover a broader range of dangerous Unicode characters. It closes potential loopholes where characters like zero-width spaces or bidirectional overrides could bypass existing ASCII-only or limited Unicode control character checks, thereby preventing potential injection attacks or misinterpretations in resource names and other inputs. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a security vulnerability by extending input validation to reject dangerous Unicode characters that were previously missed. The approach of using a shared constant for the rejected characters is sound. My review focuses on improving the performance and structure of this new validation logic, which is crucial for security-sensitive code, by suggesting a more efficient implementation using Rust's matches! macro. The accompanying tests are thorough and provide good coverage for the new checks.
Extend reject_control_chars() and validate_resource_name() to reject zero-width chars (U+200B, U+200C, U+200D, U+FEFF), bidi overrides (U+202A-U+202E), Unicode line/paragraph separators (U+2028, U+2029), and directional isolates (U+2066-U+2069). These multi-byte codepoints were silently passing the previous ASCII-range byte check, creating a potential injection vector when the CLI is driven by LLM agents. Adds 20 new tests covering all rejected categories plus documented intentional pass-throughs (homoglyphs, overlong names).
… using matches! Switch from a REJECTED_UNICODE_CHARS &[char] constant + .contains() (O(M) linear scan per character) to an is_rejected_unicode(c: char) -> bool helper that uses the matches! macro with char ranges. This gives O(1) per character and reads more clearly at call sites via .any(is_rejected_unicode).
11f4e15 to
100d0ea
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances input validation by rejecting a range of dangerous Unicode characters, which is a great security improvement. My review identifies a recurring performance issue where the new checks introduce a second iteration over the input string. I've recommended combining these checks into a single pass for improved performance and efficiency.
Address review feedback: replace the two-iteration approach (one byte scan + one char scan) in reject_control_chars with a single char loop, and merge the separate is_control / is_rejected_unicode guards in validate_resource_name into one any() call. Avoids iterating the input string twice, closing the O(N*M) concern raised by the reviewer.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances input validation by rejecting a range of dangerous Unicode characters, such as zero-width spaces, bidirectional overrides, and line/paragraph separators. The changes correctly move from a byte-based check to a character-based one to handle multi-byte Unicode characters properly. The new validation is applied to both directory paths and resource names. The addition of comprehensive tests for the new Unicode checks is also a great improvement. I have one suggestion to improve code clarity in one of the validation functions.
Summary
reject_control_chars()used a byte-level ASCII check (b < 0x20 || b == 0x7F) that silently passed all multi-byte Unicode — zero-width chars, bidi overrides, and Unicode line/paragraph separators could slip through uncheckedvalidate_resource_name()usedc.is_control()(Unicode "Cc" only), missing "Cf" (format) and "Zl"/"Zp" (separator) categories — the same dangerous charsREJECTED_UNICODE_CHARSconstant covering U+200B–U+200D, U+FEFF, U+202A–U+202E, U+2028–U+2029, and U+2066–U+2069; both validators now check against itTest plan
cargo test validate— all 20 new Unicode tests pass alongside existing suitevalidate_resource_name("foo\u{200B}bar")returnsErrvalidate_resource_name("foo\u{202E}bar")returnsErr(RTL override)validate_resource_name("日本語")still returnsOk(normal Unicode unaffected)validate_safe_output_dir("foo\u{2028}bar")returnsErr🤖 Generated with Claude Code