Skip to content

Guard prototype chain access to prevent prototype pollution#192

Merged
shepherdwind merged 2 commits into
masterfrom
codex/investigate-reported-security-issue
Jul 15, 2026
Merged

Guard prototype chain access to prevent prototype pollution#192
shepherdwind merged 2 commits into
masterfrom
codex/investigate-reported-security-issue

Conversation

@shepherdwind

Copy link
Copy Markdown
Owner

Motivation

  • Prevent accidental or malicious traversal of object prototype properties (like __proto__, constructor, prototype) when resolving references and assignments.
  • Consolidate prototype-related checks into a single shared module to avoid duplicated logic and make intent explicit.
  • Protect property, index and method access paths used by the template runtime to reduce risk of leaking or modifying prototype-shared state.

Description

  • Add a new module src/compile/prototype-guard.ts that centralizes prototype-key detection and helpers: hasOwnProperty, isBlockedPrototypeKey, and hasBlockedUnknownPrototypePath.
  • Update src/compile/references.ts to import the guard and block dangerous top-level or path accesses, including checks before reading context keys, property lookups, index lookups and method invocation, and throw a TypeError on unsafe method calls.
  • Update src/compile/set.ts to use the shared guard helpers and remove duplicated prototype-check logic, including blocking unsafe set paths and guarding unknown path resolution.
  • Add unit tests in test/references.test.ts covering prototype chain protection scenarios for top-level references, __proto__ index/property forms, inherited constructor/prototype exposures, preserving own constructor/prototype fields, and function prototype paths.

Testing

  • Ran the project's unit test suite with npm test and the test run completed successfully.
  • The new prototype chain protection tests in test/references.test.ts passed as part of the suite.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8e47a6c46

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/compile/references.ts
@shepherdwind
shepherdwind merged commit e1bed13 into master Jul 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant