Skip to content

Apply the global query param allow-list to static badges - #12177

Open
BurakErdemci wants to merge 2 commits into
badges:masterfrom
BurakErdemci:fix/static-badge-query-params
Open

BurakErdemci wants to merge 2 commits into
badges:masterfrom
BurakErdemci:fix/static-badge-query-params

Conversation

@BurakErdemci

Copy link
Copy Markdown

#10111

BaseStaticService.register handed the raw query string to coalesceBadge. Every other badge goes through handleRequest, which forwards only the keys in globalQueryParams plus the keys the service declares. That gap let #9191 add logoSize and have it work on /badge/... alone until #10110 put it on the list.

I moved the list and the filter into core/base-service/query-params.js and use it on both paths.

before after
normal badge filtered in legacy-request-handler.js filtered, same code
static badge (/badge/..., /static/v1, gitter) raw query params reach coalesceBadge global keys plus the route's queryParamSchema keys

Rendered output stays the same today, because coalesceBadge reads exactly the ten keys on the global list. A key added to one side without the other now fails the same way on every badge.

Left alone on purpose:

  • cacheSeconds and maxAge still come from the raw object on the normal path, and static badges still ignore them (they set their own cache headers).
  • The old list named 'link' twice. The Set already ignored the duplicate, so the new list names it once.

Tests: query-params.spec.js pins the list and the filter shape; base-static.spec.js is the first spec for that class and fails without the filter. I ran npm run lint, npm run prettier:check, npm run test:core (1585 passing), npm run test:entrypoint and npm run test:services -- --only=staticbadge,querystringstatic (19 passing) on Windows with Node 24.21.

One question: I export globalQueryParams only so the first spec case can check membership. Say the word and I will drop the export.

BaseStaticService passed the raw query string to coalesceBadge, while
every other badge goes through handleRequest, which only forwards the
keys in globalQueryParams plus the ones the service declares. A key
read by coalesceBadge but missing from the list therefore worked on
static badges only (badges#9191 / badges#10110).

Move the list and the filter into core/base-service/query-params.js
and use it on both paths. Legacy path behaviour is unchanged.

badges#10111
The test compared flattenQueryParams() against the exported Set, so a
key dropped from the list would have passed. Assert the literal list
instead.
@github-actions

Copy link
Copy Markdown
Contributor
Messages
📖 ✨ Thanks for your contribution to Shields, @BurakErdemci!

Generated by 🚫 dangerJS against 8b1ceee

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant