Visitar URL original
[JS] False Negative : Unsafe Html Construction · Issue #8274 · github/codeql · GitHub
The Wayback Machine - https://web.archive.org/web/20260620192609/https://github.com/github/codeql/issues/8274
Skip to content

[JS] False Negative : Unsafe Html Construction  #8274

@Naman-ntc

Description

@Naman-ntc

In the following snippet, only the middle snippet is returned as vulnerable (the first and third calls are not marked vulnerable).

For the first case, I assume that escaping single or double quotes will make the code safe. But in the third code snippet, it only escapes " and should still be marked vulnerable? It seems that

  • the query only detects attrVal.indexOf("\"") === -1 as a guard (and does not even consider attrVal.indexOf("'") === -1 as a guard)
  • does not use flow labels to check if both guards exist
module.exports.guards = function(attrVal) {
    if (attrVal.indexOf("\"") === -1 && attrVal.indexOf("'") === -1) {
        document.querySelector("#id").innerHTML = "<img alt=\"" + attrVal + "\"/>"; // OK [not reported vulnerable]
    }
    if (attrVal.indexOf("'") === -1) {
        document.querySelector("#id").innerHTML = "<img alt=\"" + attrVal + "\"/>"; // NOT OK [reported vulnerable]
    }
    if (attrVal.indexOf("\"") === -1) {
        document.querySelector("#id").innerHTML = "<img alt=\"" + attrVal + "\"/>"; // NOT OK [not reported vulnerable] [False Negative?]
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    JSquestionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions