Skip to content

rules: 12 querySelector calls interpolate page ids/roles unescaped; quotes in an id throw 'Attribute selector didn't terminate' #1276

Closed

Description

@nc9

Twelve rule call sites build CSS attribute selectors by interpolating page-controlled values without escaping, e.g. doc.querySelector(\label[for="${id}"]`). An id(orrole, etc.) containing ", ` or ] makes the selector invalid. The rule then throws Rule error: Attribute selector didn't terminate, which is reported as a fail. Values that parse but mean something else can also match the wrong element silently.

a11y/duplicate-id-aria already avoids this with a one-pass id map. Its comment explains why: CSS.escape isn't available in the compiled binary, and quotes or brackets break the selector either way. The other call sites weren't updated:

  • a11y/aria-input-field-name (2), a11y/aria-toggle-field-name (2)
  • a11y/form-labels, a11y/form-field-multiple-labels, a11y/select-name
  • a11y/aria-meter-name, a11y/aria-progressbar-name, a11y/aria-command-name, a11y/aria-required-parent
  • security/form-captcha

(git grep -nE 'querySelector(All)?\(\[^`]*="${' -- packages/rules/src`)

Seen in a ~38k-site batch on v0.0.141: one site's form produced Rule error: Attribute selector didn't terminate from 4 of these rules at once.

Acceptance Criteria

  • No rule interpolates a page-controlled value into a selector string. Ids go through a shared lookup (an id map, or a getAttribute comparison); a safe escaper that runs in the compiled binary is acceptable if one is added to parser/utils.
  • A test feeds each listed rule a form whose id/for values contain ", \, ] and a space. Each rule evaluates normally with no Rule error:, and labels still associate correctly.
  • A guard test (or lint) fails when a new querySelector(\...="${...}"...`)with a page-derived value is added underpackages/rules/src`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrulessize: Msize: S

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions