Skip to content

Commit

Permalink
fix: revert #9113, #9114, #9085 (#9230)
Browse files Browse the repository at this point in the history
Reverting the following IAST PRs: #9113, #9114, #9085

They will be re-introduced in 2.10 after some investigation, but
reverting for now to un-block the 2.9.0 release pipeline.

## Checklist

- [x] Change(s) are motivated and described in the PR description
- [x] Testing strategy is described if automated tests are not included
in the PR
- [x] Risks are described (performance impact, potential for breakage,
maintainability)
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed or label `changelog/no-changelog` is set
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/))
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))
- [x] If this PR changes the public interface, I've notified
`@DataDog/apm-tees`.

## Reviewer Checklist

- [x] Title is accurate
- [x] All changes are related to the pull request's stated goal
- [x] Description motivates each change
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- [x] Testing strategy adequately addresses listed risks
- [x] Change is maintainable (easy to change, telemetry, documentation)
- [x] Release note makes sense to a user of the library
- [x] Author has acknowledged and discussed the performance implications
of this PR as reported in the benchmarks PR comment
- [x] Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
erikayasuda committed May 10, 2024
1 parent 96e8460 commit 3c7d1d1
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 1,779 deletions.
81 changes: 25 additions & 56 deletions ddtrace/appsec/_iast/_ast/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from _ast import ImportFrom
import ast
import copy
import os
import sys
from typing import Any # noqa:F401
from typing import List # noqa:F401
Expand Down Expand Up @@ -66,9 +65,6 @@ def __init__(
"format_map": "ddtrace_aspects.format_map_aspect",
"zfill": "ddtrace_aspects.zfill_aspect",
"ljust": "ddtrace_aspects.ljust_aspect",
"split": "ddtrace_aspects.split_aspect",
"rsplit": "ddtrace_aspects.rsplit_aspect",
"splitlines": "ddtrace_aspects.splitlines_aspect",
},
# Replacement function for indexes and ranges
"slices": {
Expand All @@ -77,14 +73,10 @@ def __init__(
},
# Replacement functions for modules
"module_functions": {
"os.path": {
"basename": "ddtrace_aspects._aspect_ospathbasename",
"dirname": "ddtrace_aspects._aspect_ospathdirname",
"join": "ddtrace_aspects._aspect_ospathjoin",
"normcase": "ddtrace_aspects._aspect_ospathnormcase",
"split": "ddtrace_aspects._aspect_ospathsplit",
"splitext": "ddtrace_aspects._aspect_ospathsplitext",
}
# "BytesIO": "ddtrace_aspects.stringio_aspect",
# "StringIO": "ddtrace_aspects.stringio_aspect",
# "format": "ddtrace_aspects.format_aspect",
# "format_map": "ddtrace_aspects.format_map_aspect",
},
"operators": {
ast.Add: "ddtrace_aspects.add_aspect",
Expand Down Expand Up @@ -133,13 +125,6 @@ def __init__(
},
},
}

if sys.version_info >= (3, 12):
self._aspects_spec["module_functions"]["os.path"]["splitroot"] = "ddtrace_aspects._aspect_ospathsplitroot"

if sys.version_info >= (3, 12) or os.name == "nt":
self._aspects_spec["module_functions"]["os.path"]["splitdrive"] = "ddtrace_aspects._aspect_ospathsplitdrive"

self._sinkpoints_spec = {
"definitions_module": "ddtrace.appsec._iast.taint_sinks",
"alias_module": "ddtrace_taint_sinks",
Expand Down Expand Up @@ -507,46 +492,30 @@ def visit_Call(self, call_node): # type: (ast.Call) -> Any
if self._is_string_format_with_literals(call_node):
return call_node

# This resolve moduleparent.modulechild.name
# TODO: use the better Hdiv method with a decorator
func_value = getattr(func_member, "value", None)
func_value_value = getattr(func_value, "value", None) if func_value else None
func_value_value_id = getattr(func_value_value, "id", None) if func_value_value else None
func_value_attr = getattr(func_value, "attr", None) if func_value else None
func_attr = getattr(func_member, "attr", None)
aspect = None
if func_value_value_id or func_attr:
if func_value_value_id and func_value_attr:
# e.g. "os.path" or "one.two.three.whatever" (all dotted previous tokens with be in the id)
key = func_value_value_id + "." + func_value_attr
elif func_value_attr:
# e.g os
key = func_attr
else:
key = None

if key:
module_dict = self._aspect_modules.get(key, None)
aspect = module_dict.get(func_attr, None) if module_dict else None
if aspect:
# Create a new Name node for the replacement and set it as node.func
call_node.func = self._attr_node(call_node, aspect)
self.ast_modified = call_modified = True
aspect = self._aspect_methods.get(method_name)

if not aspect:
# Not a module symbol, check if it's a known method
aspect = self._aspect_methods.get(method_name)
if aspect:
# Move the Attribute.value to 'args'
new_arg = func_member.value
call_node.args.insert(0, new_arg)
# Send 1 as flag_added_args value
call_node.args.insert(0, self._int_constant(call_node, 1))

# Insert None as first parameter instead of a.b.c.method
# to avoid unexpected side effects such as a.b.read(4).method
call_node.args.insert(0, self._none_constant(call_node))

# Create a new Name node for the replacement and set it as node.func
call_node.func = self._attr_node(call_node, aspect)
self.ast_modified = call_modified = True

elif hasattr(func_member.value, "id") or hasattr(func_member.value, "attr"):
aspect = self._aspect_modules.get(method_name, None)
if aspect:
# Move the Attribute.value to 'args'
new_arg = func_member.value
call_node.args.insert(0, new_arg)
# Send 1 as flag_added_args value
call_node.args.insert(0, self._int_constant(call_node, 1))

# Insert None as first parameter instead of a.b.c.method
# to avoid unexpected side effects such as a.b.read(4).method
call_node.args.insert(0, self._none_constant(call_node))
# Send 0 as flag_added_args value
call_node.args.insert(0, self._int_constant(call_node, 0))
# Move the Function to 'args'
call_node.args.insert(0, call_node.func)

# Create a new Name node for the replacement and set it as node.func
call_node.func = self._attr_node(call_node, aspect)
Expand Down
74 changes: 0 additions & 74 deletions ddtrace/appsec/_iast/_taint_tracking/Aspects/AspectSplit.cpp

This file was deleted.

18 changes: 0 additions & 18 deletions ddtrace/appsec/_iast/_taint_tracking/Aspects/AspectSplit.h

This file was deleted.

0 comments on commit 3c7d1d1

Please sign in to comment.