Repository navigation
fix(core): allowlist the /percy/log level so request input never drives dynamic dispatch (PER-8625) #2426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): allowlist the /percy/log level so request input never drives dynamic dispatch (PER-8625) #2426
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,9 @@ function assertNotCrossOrigin(req) { | |
| } | ||
| } | ||
|
|
||
| // Log levels an SDK may forward through POST /percy/log. | ||
| const SDK_LOG_LEVELS = new Set(['debug', 'info', 'warn', 'error']); | ||
|
|
||
| // Create a Percy CLI API server instance | ||
| export function createPercyServer(percy, port) { | ||
| let pkg = getPackageJSON(import.meta.url); | ||
|
|
@@ -319,7 +322,20 @@ export function createPercyServer(percy, port) { | |
| const message = req.body.message; | ||
| const meta = req.body.meta || {}; | ||
|
|
||
| log[level](message, meta); | ||
| // `level` is attacker-controlled input on an unauthenticated endpoint, so | ||
| // it must never be used as a dynamic property key on the logger object | ||
| // (CWE-1321 / PER-8606, PER-8625). Only the four log levels are dispatched; | ||
| // anything else (`__proto__`, `constructor`, `loglevel`, ...) is rejected. | ||
| if (!SDK_LOG_LEVELS.has(level)) { | ||
| return res.json(400, { error: 'Invalid log level' }); | ||
| } | ||
|
|
||
| switch (level) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Low] Switch is redundant once the guard has run After Suggestion: Keep the switch if it is deliberate defense in depth against any dynamic property access, and say so in the comment. Otherwise collapse it back to the guarded dynamic call. Reviewer: stack-code-reviewer |
||
| case 'debug': log.debug(message, meta); break; | ||
| case 'info': log.info(message, meta); break; | ||
| case 'warn': log.warn(message, meta); break; | ||
| default: log.error(message, meta); | ||
| } | ||
|
|
||
| res.json(200, { success: true }); | ||
| }) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Low] Level allowlist duplicates the logger's own level list
This set repeats the levels already defined as
LOG_LEVELSinpackages/logger/src/logger.js, which is not exported. If a level is ever added or renamed there without updating this copy, the two drift silently and this endpoint starts rejecting a valid level.Suggestion: Export the level list from
@percy/loggerand import it here rather than keeping a second hardcoded copy. Fine as a follow-up.Reviewer: stack-code-reviewer