Skip to content

diff_test does not escape the error message string and allows for shell injection #1064

@kharvd

Description

@kharvd

Strings in failure_message are interpolated into the generated shell script without escaping special characters:

diff_test(
    name ="foo",
    file1 = ":a.txt",
    file2 = ":b.txt",
    failure_message = "shell injection: `echo hello world`",
)

Actual test output:

exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:foo
-----------------------------------------------------------------------------
1d0
< 1
FAIL: files "a.txt" and "b.txt" differ. shell injection: hello world

expected:

exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:foo
-----------------------------------------------------------------------------
1d0
< 1
FAIL: files "a.txt" and "b.txt" differ. shell injection: `echo hello world`

Same issue with using failure_message = "$(echo hello world)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedAspect isn't prioritizing this, but the community could

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions