Skip to content

[JavaScript] False Negative - Taint tracking through closure #20883

@yonajix

Description

@yonajix

I've been trying to track this simple Code Injection Vulnerability with CodeQL and I've noticed its having problems tracking the taint through a closure boundary:

function process(input) {
    const tokens = [{ text: input }];
    
    return {
        execute() {
            for (const token of tokens) {
                eval(token.text);  
            }
        }
    };
}

let userInput = location.hash.substring(1);
const result = process(userInput);
result.execute();

I ran the CodeInjection query for JS against this and got nothing.

I made a simple flow tracking query where I set the CodeInjection sink to any() and I noticed taint tracking stops at const tokens = [{ text: input }];

I made a simpler example without the closure:

function process(input) {
    const tokens = [{ text: input }];

    for (const token of tokens) {
        eval(token.text); 
    }
}


let userInput = location.hash.substring(1);
process(userInput);

the CodeInjection query catches this so it can't be the for loop causing this miss on its own.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions