Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iast): partial matches on function names should not be patched [backport 2.11] #11017

Open
wants to merge 2 commits into
base: 2.11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ddtrace/appsec/_iast/_ast/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _should_replace_with_taint_sink(self, call_node: ast.Call, is_function: bool
if function_name in self._taint_sink_replace_disabled:
return False

return any(allowed in function_name for allowed in self._taint_sink_replace_any)
return function_name in self._taint_sink_replace_any

def _add_original_function_as_arg(self, call_node: ast.Call, is_function: bool) -> Any:
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fixes:
- |
Code security: This fix resolves an issue where partial matches on function names we aimed to patch were being patched instead of full matches on them.
15 changes: 15 additions & 0 deletions tests/appsec/iast/_ast/test_ast_patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,18 @@ def test_module_path_none(caplog):
with caplog.at_level(logging.DEBUG), mock.patch("ddtrace.internal.module.Path.resolve", side_effect=AttributeError):
assert ("", "") == astpatch_module(__import__("tests.appsec.iast.fixtures.ast.str.class_str", fromlist=[None]))
assert "astpatch_source couldn't find the module: tests.appsec.iast.fixtures.ast.str.class_str" in caplog.text


@pytest.mark.parametrize(
"module_name",
[
("tests.appsec.iast.fixtures.ast.other.globals_builtin"),
],
)
def test_astpatch_globals_module_unchanged(module_name):
module_path, new_source = astpatch_module(__import__(module_name, fromlist=[None]))
assert ("", "") == (module_path, new_source)
if ("", "") != (module_path, new_source):
gnufede marked this conversation as resolved.
Show resolved Hide resolved
new_code = astunparse.unparse(new_source)
assert not new_code.startswith("\nimport ddtrace.appsec._iast")
assert "ddtrace_taint_sinks.ast_function(globals, 0)" not in new_code
3 changes: 3 additions & 0 deletions tests/appsec/iast/fixtures/ast/other/globals_builtin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python3

_globals = globals()
Loading