Skip to content

[BUG] Invalid XPath extractor expressions compile successfully and are silently skipped #7750

Description

@james-yusuke

Is there an existing issue for this?

Current Behavior

Extractor.CompileExtractors() accepts invalid XPath expressions such as //a[ and unknown-function(). When extraction runs, htmlquery.QueryAll / xmlquery.QueryAll returns an error and the extractor silently skips the expression. Unlike invalid regex, JSON or DSL expressions, the author gets no compilation error identifying the mistake.

Expected Behavior

Reject invalid XPath expressions during extractor compilation, including the offending expression and parser error in the diagnostic. Valid HTML and XML extraction should continue to work.

Steps To Reproduce

Inside the nuclei module, construct an extractor and compile it:

e := &extractors.Extractor{
    Type: extractors.ExtractorTypeHolder{ExtractorType: extractors.XPathExtractor},
    XPath: []string{"//a["},
}
fmt.Println(e.CompileExtractors()) // currently <nil>
fmt.Println(e.ExtractXPath(`<html><body><a>link</a></body></html>`)) // map[]

This also occurs when an invalid expression follows a valid one, e.g. []string{"//a", "//p["}.

Environment

  • OS: macOS / arm64
  • Nuclei: dev at 66068db
  • Go: go1.26.5

Anything else?

I reproduced the missing validation with regression tests: all three invalid-expression cases failed on the unmodified implementation because compilation returned nil. The fix uses the existing github.com/antchfx/xpath dependency's compiler and does not change extraction behavior.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions