fix(security): validate resource names in watch and subscribe helpers#409
Conversation
Add `validate_resource_name()` checks to the `--subscription` flag in `gmail +watch` and to auto-generated slugs in `events +subscribe`. This prevents path traversal and query injection via Pub/Sub resource names, consistent with the existing validation on `--project`. Closes googleworkspace#408
🦋 Changeset detectedLatest commit: 6477b53 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 |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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 posture of the application by introducing robust validation for resource names used in Pub/Sub operations. By validating user-supplied subscription names and internally generated slugs, it effectively mitigates risks associated with path traversal and query injection, ensuring that only safe and valid identifiers are used when interacting with Google Cloud Pub/Sub. 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 enhances security by adding validation for resource names in gmail +watch and events +subscribe helpers. This prevents potential path traversal and query injection vulnerabilities by applying validate_resource_name to user-provided subscription names and auto-generated slugs before they are used in API URLs. The accompanying unit tests effectively verify these new security measures.
My feedback includes one point regarding the strictness of the validate_resource_name function, which may inadvertently reject some valid Pub/Sub resource names.
|
I have signed the CLA. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses a security vulnerability by adding validation for resource names used in constructing Pub/Sub API URLs. Specifically, it adds validate_resource_name() for the auto-generated slug in events +subscribe and for the user-provided --subscription argument in gmail +watch. This prevents potential path traversal and query injection attacks. The changes are correct, well-targeted, and include new tests to verify the fix. The implementation is solid and effectively mitigates the described vulnerability.
Summary
validate_resource_name()to the--subscriptionflag ingmail +watch(parse_watch_args)validate_resource_name()to auto-generated slugs inevents +subscribebefore they are embedded in Pub/Sub topic/subscription URLs../) and query injection (?,#) via Pub/Sub resource names, consistent with existing validation on--projectDetails
The
--subscriptionvalue ingmail +watchwas interpolated directly into Pub/Sub API URLs without passing throughvalidate_resource_name(). Similarly,events +subscribevalidated the user-supplied--subscriptionflag but not the auto-generated slug fromderive_slug_from_event_types().Both paths now validate resource names before URL construction.
Test plan
--subscriptionwith../traversal is rejected (watch + subscribe)--subscriptionwith control characters is rejected (watch + subscribe)Closes #408