Skip to content

fix(security): validate resource names in watch and subscribe helpers#409

Open
anshul-garg27 wants to merge 2 commits intogoogleworkspace:mainfrom
anshul-garg27:fix/validate-resource-names-watch-subscribe
Open

fix(security): validate resource names in watch and subscribe helpers#409
anshul-garg27 wants to merge 2 commits intogoogleworkspace:mainfrom
anshul-garg27:fix/validate-resource-names-watch-subscribe

Conversation

@anshul-garg27
Copy link
Contributor

Summary

  • Add validate_resource_name() to the --subscription flag in gmail +watch (parse_watch_args)
  • Add validate_resource_name() to auto-generated slugs in events +subscribe before they are embedded in Pub/Sub topic/subscription URLs
  • This prevents path traversal (../) and query injection (?, #) via Pub/Sub resource names, consistent with existing validation on --project

Details

The --subscription value in gmail +watch was interpolated directly into Pub/Sub API URLs without passing through validate_resource_name(). Similarly, events +subscribe validated the user-supplied --subscription flag but not the auto-generated slug from derive_slug_from_event_types().

Both paths now validate resource names before URL construction.

Test plan

  • Added test: --subscription with ../ traversal is rejected (watch + subscribe)
  • Added test: --subscription with control characters is rejected (watch + subscribe)
  • Added test: valid subscription names still pass (watch)
  • Added test: auto-generated slugs pass validation (subscribe)
  • Existing tests continue to pass

Closes #408

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-bot
Copy link

changeset-bot bot commented Mar 11, 2026

🦋 Changeset detected

Latest commit: 6477b53

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

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

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Mar 11, 2026
@google-cla
Copy link

google-cla bot commented Mar 11, 2026

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Security Enhancement: Implemented validate_resource_name() for the --subscription flag in gmail +watch to prevent path traversal and query injection vulnerabilities.
  • Auto-generated Slug Validation: Added validate_resource_name() to auto-generated slugs in events +subscribe before they are used in Pub/Sub topic/subscription URLs, addressing potential security risks.
  • Consistent Validation: Ensured consistency with existing validation on the --project flag by applying similar resource name validation to subscription and slug names.
  • Comprehensive Testing: Introduced new tests to specifically cover rejection of path traversal and control characters in subscription names for both watch and subscribe commands, as well as validation for auto-generated slugs.
Changelog
  • .changeset/validate-resource-names-watch-subscribe.md
    • Added a new changeset entry documenting the security fix for resource name validation.
  • src/helpers/events/subscribe.rs
    • Introduced validate_resource_name() call for auto-generated slugs before constructing Pub/Sub topic/subscription URLs.
    • Added new unit tests to verify rejection of path traversal and control characters in subscription names.
    • Added a test to ensure auto-generated slugs pass resource name validation.
  • src/helpers/gmail/watch.rs
    • Implemented validate_resource_name() for the --subscription flag.
    • Added new unit tests to confirm rejection of invalid subscription names (path traversal, control characters) and successful parsing of valid ones.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 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.

@anshul-garg27
Copy link
Contributor Author

I have signed the CLA.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing validate_resource_name on subscription/topic names in watch and subscribe helpers

2 participants