Skip to content

Read contained value sets only at their own list positions - #10

Draft
PSchmiedmayer wants to merge 2 commits into
anvil-authoring-correctnessfrom
fix/value-set-field-keys
Draft

PSchmiedmayer wants to merge 2 commits into
anvil-authoring-correctnessfrom
fix/value-set-field-keys

Conversation

@PSchmiedmayer

Copy link
Copy Markdown
Member

♻️ Current situation & Problem

ValueSetEditor is part of the public React API and takes the position of a value set in the questionnaire's contained list as its index prop.
The editor and its id field read contained[index] and then write to the entry they found, for example target.id = next when the id is renamed.
An index such as "__proto__" or "constructor" would resolve to Array.prototype or the Array constructor instead of a list entry.
The existing isValueSet and isObject checks reject those values today, but the write path itself does not limit the lookup to list entries, and CodeQL reports it as a prototype-polluting assignment (js/prototype-polluting-assignment).

⚙️ Release Notes

  • ValueSetEditor reads a contained entry only when index is a number that names one of the list's own entries.
    Any other index, including a numeric string such as "0", renders nothing and never reaches a store update.
  • All reads of contained[index] in the value set editor go through one helper, so the rendered editor, title and code edits, and id renames use the same check:
const containedAt = (contained: unknown, index: unknown): unknown =>
  (
    Array.isArray(contained) &&
    typeof index === "number" &&
    Object.hasOwn(contained, index)
  ) ?
    contained[index]
  : undefined;

The number check rejects every string key before the lookup, and the own-entry check accepts exactly the positions that exist in the array.
Together they cover inherited keys that a list of forbidden names could miss.
Valid indices behave as before; a contained value that is not an array is now ignored here, as containedValueSets and removeContained already do.

📚 Documentation

The helper's inline documentation states why the lookup is restricted.
The public API is unchanged, so the package READMEs need no update.

✅ Testing

  • valueSets.test.tsx adds a case where a host plugin renders ValueSetEditor for index 0 and for the keys "__proto__", "constructor", "prototype" and "0".
    Only the editor for index 0 appears, renaming its id still updates the document, and neither Array.prototype nor Object.prototype gains an id property.

Code of Conduct & Contributing Guidelines

By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

ValueSetEditor takes the position of a value set in the contained list
as a prop and writes to the entry it finds there. Read that entry only
when the index is a number naming one of the list's own entries, so a
key such as __proto__ cannot resolve to a prototype.
@coderabbitai

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@PSchmiedmayer
PSchmiedmayer added this pull request to stack #9 December 4, 2026 22:51
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