Skip to content

Commit

Permalink
Merge branch 'main' into avara1986/refactor_iast_request_context_to_core
Browse files Browse the repository at this point in the history
  • Loading branch information
avara1986 authored Oct 14, 2024
2 parents e4cc5f4 + a72b931 commit d057d9d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ddtrace/appsec/_iast/_ast/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,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 @@ -208,3 +208,18 @@ def test_astpatch_bytesio_module_changed(module_name):
"\nimport ddtrace.appsec._iast._taint_tracking.aspects as ddtrace_aspects"
)
assert "ddtrace_aspects.bytesio_aspect(" in new_code


@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):
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()

0 comments on commit d057d9d

Please sign in to comment.