You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(iast): prepare aspect for unexpected args (#7491) [backport 2.0] (#7574)
IAST: This PR addresses two interconnected issues in the AST patching
process that replaces code with aspects:
1. Resolves a bug that occurs during AST patching, where a custom
function or method call could be replaced by one of our aspects. In
situations where the function has a different number of arguments than
our aspects, a runtime ``TypeError`` occurs. This is fixed by ensuring
that all aspects now receive ``(*args, **kwargs)`` and pass them
appropriately to the original custom function or method.
2. Fixes another bug in the AST patching process, where the module of a
function is incorrectly passed as the first argument to the aspect. In
cases where it's a custom function, our logic inadvertently passes the
module received as the first argument to the original function. The
solution involves introducing a flag to the aspect's arguments,
indicating the additional arguments added during patching. This allows
us to remove them before calling the original function or method.
- [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] Risk is outlined (performance impact, potential for breakage,
maintainability, etc).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed. If no release note is required, add label
`changelog/no-changelog`.
- [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] Title is accurate.
- [x] No unnecessary changes are introduced.
- [x] Description motivates each change.
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes unless absolutely necessary.
- [x] Testing strategy adequately addresses listed risk(s).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] Release note makes sense to a user of the library.
- [x] Reviewer has explicitly 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)
- [x] If this PR touches code that signs or publishes builds or
packages, or handles credentials of any kind, I've requested a review
from `@DataDog/security-design-and-guidance`.
- [x] This PR doesn't touch any of that.
---------
Co-authored-by: Alberto Vara <[email protected]>
(cherry picked from commit d5caa6c)
0 commit comments