Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: guard CONTEXTUAL_RISK_FLAGS lookup against prototype pollution#377

Merged
tmchow merged 1 commit into
mainfrom
feat/fix-contextual-risk-flags
Mar 25, 2026
Merged

fix: guard CONTEXTUAL_RISK_FLAGS lookup against prototype pollution#377
tmchow merged 1 commit into
mainfrom
feat/fix-contextual-risk-flags

Conversation

@tmchow
Copy link
Copy Markdown
Collaborator

@tmchow tmchow commented Mar 25, 2026

Summary

  • Fixes a TypeError in extract-commands.mjs where bracket-notation lookup on CONTEXTUAL_RISK_FLAGS could return inherited prototype methods (e.g. constructor, toString) that don't have .has(), crashing the script on certain command tokens.
  • Guards the lookup with Object.hasOwn() so only own properties (-f, -v) are returned.
  • Extracts isRiskFlag and normalize into a separate normalize.mjs module for testability.
  • Adds 14 regression tests covering prototype property names, global/contextual risk flags, and core normalization behavior.

Test plan

  • bun test — all 386 tests pass
  • Smoke-tested extract-commands.mjs end-to-end — runs without errors
  • Verified prototype property tokens (constructor, toString, valueOf, hasOwnProperty, __proto__) no longer throw

Bracket-notation lookup on a plain object returned inherited prototype
methods (e.g. constructor, toString) which don't have .has(), causing a
TypeError at runtime. Guard with Object.hasOwn() so only own properties
are returned.

Extract normalization logic into scripts/normalize.mjs for testability
and add regression tests covering prototype property names.
@tmchow tmchow merged commit 8ebc77b into main Mar 25, 2026
2 checks passed
This was referenced Mar 25, 2026
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.

1 participant