Skip to content

[repo-monitor] High: XPath injection via unsanitized id attribute value #5

@Liohtml

Description

@Liohtml

Summary

HTML element id attribute values are embedded directly into XPath expressions using single-quote delimiters without escaping, enabling XPath injection from page content.

Location

  • File: src/parser/selector_generation.rs
  • Line(s): 50

Severity

High

Details

parts.push(format!("{}[@id='{}']", tag, id.as_str()));

An HTML element with id="foo' or '1'='1" produces the XPath div[@id='foo' or '1'='1'], which is valid but semantically wrong and matches unintended nodes. Adversarial page content could cause incorrect element identification.

Suggested Fix

Escape single quotes in the ID value before embedding:

let escaped_id = id.as_str().replace('\'', "\\'");
parts.push(format!("{}[@id='{}']" , tag, escaped_id));

Automated finding by repo-monitor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions