Skip to content

Validate route identifiers as single path segments - #52

Merged
markdorison merged 1 commit into
mainfrom
markdorison/validate-route-segments
Sep 23, 2026
Merged

markdorison merged 1 commit into
mainfrom
markdorison/validate-route-segments

Conversation

@markdorison

Copy link
Copy Markdown
Contributor

What

Named helpers now reject any org, pipeline, build, number, job, or id argument that isn't a single URL path segment. Invalid values raise Buildkit::InvalidRouteSegment (a subclass of ArgumentError) before any request goes out.

  • Added Client#route_segment: an allow list of RFC 3986 unreserved characters that also rejects ., .., empty strings, and nil.
  • Wrapped every interpolated identifier in all six helper modules (agents, artifacts, builds, jobs, organizations, pipelines).
  • Rejects rather than percent-encodes: Client#request already escapes the whole path, so encoded segments would be escaped twice, and changing that would affect the public get/post/put methods.
  • Documented the contract in the README and module docs, and bumped the version to 1.6.2.

Why

Helpers interpolate identifiers into the request path without validating them, so an identifier containing path or query delimiters could send the request to a different endpoint than the helper intends.

Upgrade note

Code that passes a malformed identifier now gets Buildkit::InvalidRouteSegment locally instead of a Buildkit::NotFound from the API. If identifiers come from user input, validate them at your boundary rather than rescuing this error.

Testing

Tests cover: the two reported rerouting cases, a query-only build number, dot segments, a percent-encoded delimiter, empty and nil values, and the ArgumentError contract. The cases span org, build, build number, job, pipeline, and agent id arguments; the existing cassette specs confirm valid identifiers still hit the recorded URLs.

Named helpers interpolated org, pipeline, build, number, job, and id arguments directly into the request path, so identifiers containing path or query delimiters could send a request to a different endpoint. Each identifier now must match the RFC 3986 unreserved set and must not be a dot segment; otherwise Buildkit::InvalidRouteSegment (an ArgumentError) is raised before any request is sent.
@markdorison
markdorison merged commit 80107da into main Sep 23, 2026
8 checks passed
@markdorison
markdorison deleted the markdorison/validate-route-segments branch September 23, 2026 14:21

This branch was successfully deployed

1 active deployment
rubygems 76224bdb Deployed Sep 23, 2026 by shopify-shipit[bot]
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