logo

Database

Go Xpath Unsanitized Input Query

Description

Detects potential XPath injection vulnerabilities in Go applications using the xmlpath.v2 library. XPath injection occurs when untrusted user input is used directly in XPath queries without proper sanitization, which could allow attackers to modify the query logic and access unauthorized data.

Weakness:

021 - XPath injection

Category: Unexpected Injection

Detection Strategy

    Check if the Go code imports the gopkg.in/xmlpath.v2 library

    Look for calls to suspicious XPath query methods

    Verify if the method parameters contain user-controlled input

    Report a vulnerability when user input flows into XPath query methods without proper sanitization

Vulnerable code example

package main

import (
    "fmt"
    "net/http"
    "gopkg.in/xmlpath.v2"
)
...

✅ Secure code example

package main

import (
    "fmt"
    "net/http"
    "regexp"
    "gopkg.in/xmlpath.v2"
)...