fix: arrows are allowed as the label value parameter#2851
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
|
I think this is intended |
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughThe PR updates the badge endpoint's input validation to permit semver range operators ( ChangesBadge schema and e2e validation
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
server/api/registry/badge/[type]/[...pkg].get.ts (1)
17-17: ⚡ Quick winConsider blocking single quotes for consistency.
The regex
/^[^"&]*$/blocks double quotes but permits single quotes. If the goal is to prevent injection attacks, single quotes should also be rejected since they can be used similarly to double quotes in many contexts.🛡️ Proposed fix to block both quote types
-const SafeStringSchema = v.pipe(v.string(), v.regex(/^[^"&]*$/, 'Invalid characters')) +const SafeStringSchema = v.pipe(v.string(), v.regex(/^[^"'&]*$/, 'Invalid characters'))🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@server/api/registry/badge/`[type]/[...pkg].get.ts at line 17, The current input validation uses the regex `/^[^"&]*$/` which blocks double quotes but allows single quotes; update the validation to reject both single and double quotes by replacing that pattern with one that excludes both quote characters (e.g., a pattern that disallows ' and "), and apply this change where the regex `/^[^"&]*$/` is used in server/api/registry/badge/[type]/[...pkg].get.ts so inputs cannot contain either quote type.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@server/api/registry/badge/`[type]/[...pkg].get.ts:
- Around line 16-17: SafeStringSchema currently allows < and > (and allows
single quotes) which can enable XSS/SVG injection when the validated value is
embedded into the badge SVG/HTML; update the validation and/or output encoding:
tighten SafeStringSchema to reject characters that can break XML/HTML contexts
(for example ensure it disallows <, >, &, " and '), or replace the regex with a
conservative whitelist (alphanumeric, dash, underscore, space, max length) and
then always XML-escape/HTML-encode the value before inserting into the SVG
template in the handler that renders the badge (refer to SafeStringSchema and
the badge rendering path that consumes its value). Ensure the sanitizer and the
final output encoding are both in place rather than relying on one or the other.
---
Nitpick comments:
In `@server/api/registry/badge/`[type]/[...pkg].get.ts:
- Line 17: The current input validation uses the regex `/^[^"&]*$/` which blocks
double quotes but allows single quotes; update the validation to reject both
single and double quotes by replacing that pattern with one that excludes both
quote characters (e.g., a pattern that disallows ' and "), and apply this change
where the regex `/^[^"&]*$/` is used in
server/api/registry/badge/[type]/[...pkg].get.ts so inputs cannot contain either
quote type.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 82d27521-bafa-4c59-83ac-fc1b9bf3dd5c
📒 Files selected for processing (2)
server/api/registry/badge/[type]/[...pkg].get.tstest/e2e/badge.spec.ts
| // Allow semver range operators like >= and <= while still rejecting quotes and ampersands. | ||
| const SafeStringSchema = v.pipe(v.string(), v.regex(/^[^"&]*$/, 'Invalid characters')) |
There was a problem hiding this comment.
❓ Verification inconclusive
🏁 Script executed:
#!/bin/bash
# Description: Check how the value parameter from SafeStringSchema is used downstream
# Find where SafeStringSchema validation is applied and trace the value usage
rg -n -A 10 "SafeStringSchema" --type=ts
# Look for SVG rendering or badge generation that uses the value parameter
rg -n -B 3 -A 5 "value.*badge|badge.*value" --type=ts -g 'server/api/registry/badge/**'
# Check for any escaping functions or sanitization
rg -n "escape|sanitize|encode" --type=ts -g 'server/api/registry/badge/**'Repository: npmx-dev/npmx.dev
Length of output: 1912
Review SafeStringSchema badge value sanitisation for XSS/SVG injection
The updated regex in server/api/registry/badge/[type]/[...pkg].get.ts permits < and > while only rejecting " and &. If the validated value is embedded into the badge’s SVG/HTML without strict escaping/encoding, this can enable XSS. Also the pattern is inconsistent in that it blocks double quotes but not single quotes—either block ' too or document why it’s safe.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@server/api/registry/badge/`[type]/[...pkg].get.ts around lines 16 - 17,
SafeStringSchema currently allows < and > (and allows single quotes) which can
enable XSS/SVG injection when the validated value is embedded into the badge
SVG/HTML; update the validation and/or output encoding: tighten SafeStringSchema
to reject characters that can break XML/HTML contexts (for example ensure it
disallows <, >, &, " and '), or replace the regex with a conservative whitelist
(alphanumeric, dash, underscore, space, max length) and then always
XML-escape/HTML-encode the value before inserting into the SVG template in the
handler that renders the badge (refer to SafeStringSchema and the badge
rendering path that consumes its value). Ensure the sanitizer and the final
output encoding are both in place rather than relying on one or the other.
|
Maybe you can replace it to unicode or html-entities? (I'm not sure it will work, but it's worth a try) |
|
This seems like a good idea; let's keep the status quo. |
🔗 Linked issue
🧭 Context
The
valueparameter can be passed as an arrow string, just like in the test cases.📚 Description