-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(asm): add SSRF support for webbrowser.open (#9209)
## Description Add SSRF taint sink support for the stdlib `webbrowser` module. ## 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) --------- Signed-off-by: Juanjo Alvarez <juanjo.alvarezmartinez@datadoghq.com> Co-authored-by: Alberto Vara <alberto.vara@datadoghq.com>
- Loading branch information
Showing
6 changed files
with
213 additions
and
68 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
Trace the standard library ``webbrowser`` library to trace | ||
HTTP requests and detect SSRF vulnerabilities. It is enabled by default | ||
if ``DD_IAST_ENABLED`` is set to ``True`` (for detecting sink points) and/or | ||
``DD_ASM_ENABLED`` is set to ``True`` (for exploit prevention). | ||
""" | ||
from .patch import get_version | ||
from .patch import patch | ||
from .patch import unpatch | ||
|
||
|
||
__all__ = ["patch", "unpatch", "get_version"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import webbrowser | ||
|
||
from ddtrace.appsec._common_module_patches import wrapped_request_D8CB81E472AF98A2 as _wrap_open | ||
from ddtrace.appsec._iast._metrics import _set_metric_iast_instrumented_sink | ||
from ddtrace.appsec._iast.constants import VULN_SSRF | ||
from ddtrace.settings.asm import config as asm_config | ||
from ddtrace.vendor.wrapt import wrap_function_wrapper as _w | ||
|
||
from ..trace_utils import unwrap as _u | ||
|
||
|
||
def get_version(): | ||
# type: () -> str | ||
return "" | ||
|
||
|
||
def patch(): | ||
"""patch the built-in webbrowser methods for tracing""" | ||
if getattr(webbrowser, "__datadog_patch", False): | ||
return | ||
webbrowser.__datadog_patch = True | ||
|
||
_w("webbrowser", "open", _wrap_open) | ||
|
||
if asm_config._iast_enabled: | ||
_set_metric_iast_instrumented_sink(VULN_SSRF) | ||
|
||
|
||
def unpatch(): | ||
"""unpatch any previously patched modules""" | ||
if not getattr(webbrowser, "__datadog_patch", False): | ||
return | ||
webbrowser.__datadog_patch = False | ||
|
||
_u(webbrowser, "open") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters