-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '3.x-staging' into yunkim/openai-drop-metrics-logs
- Loading branch information
Showing
47 changed files
with
883 additions
and
1,191 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"header_injection": True, | ||
"weak_cipher": True, | ||
"weak_hash": True, | ||
"xss": True, | ||
} | ||
|
||
|
||
|
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,78 @@ | ||
from typing import Text | ||
|
||
from ddtrace.appsec._common_module_patches import try_unwrap | ||
from ddtrace.appsec._constants import IAST_SPAN_TAGS | ||
from ddtrace.appsec._iast import oce | ||
from ddtrace.appsec._iast._iast_request_context import is_iast_request_enabled | ||
from ddtrace.appsec._iast._metrics import _set_metric_iast_executed_sink | ||
from ddtrace.appsec._iast._metrics import _set_metric_iast_instrumented_sink | ||
from ddtrace.appsec._iast._metrics import increment_iast_span_metric | ||
from ddtrace.appsec._iast._patch import set_and_check_module_is_patched | ||
from ddtrace.appsec._iast._patch import set_module_unpatched | ||
from ddtrace.appsec._iast._patch import try_wrap_function_wrapper | ||
from ddtrace.appsec._iast._taint_tracking._taint_objects import is_pyobject_tainted | ||
from ddtrace.appsec._iast.constants import VULN_XSS | ||
from ddtrace.appsec._iast.taint_sinks._base import VulnerabilityBase | ||
from ddtrace.internal.logger import get_logger | ||
from ddtrace.settings.asm import config as asm_config | ||
|
||
|
||
log = get_logger(__name__) | ||
|
||
|
||
@oce.register | ||
class XSS(VulnerabilityBase): | ||
vulnerability_type = VULN_XSS | ||
|
||
|
||
def get_version() -> Text: | ||
return "" | ||
|
||
|
||
def patch(): | ||
if not asm_config._iast_enabled: | ||
return | ||
|
||
if not set_and_check_module_is_patched("flask", default_attr="_datadog_xss_patch"): | ||
return | ||
if not set_and_check_module_is_patched("django", default_attr="_datadog_xss_patch"): | ||
return | ||
if not set_and_check_module_is_patched("fastapi", default_attr="_datadog_xss_patch"): | ||
return | ||
|
||
try_wrap_function_wrapper( | ||
"django.utils.safestring", | ||
"mark_safe", | ||
_iast_django_xss, | ||
) | ||
|
||
try_wrap_function_wrapper( | ||
"django.template.defaultfilters", | ||
"mark_safe", | ||
_iast_django_xss, | ||
) | ||
|
||
_set_metric_iast_instrumented_sink(VULN_XSS) | ||
|
||
|
||
def unpatch(): | ||
try_unwrap("django.utils.safestring", "mark_safe") | ||
try_unwrap("django.template.defaultfilters", "mark_safe") | ||
|
||
set_module_unpatched("flask", default_attr="_datadog_xss_patch") | ||
set_module_unpatched("django", default_attr="_datadog_xss_patch") | ||
set_module_unpatched("fastapi", default_attr="_datadog_xss_patch") | ||
|
||
|
||
def _iast_django_xss(wrapped, instance, args, kwargs): | ||
if args and len(args) >= 1: | ||
_iast_report_xss(args[0]) | ||
return wrapped(*args, **kwargs) | ||
|
||
|
||
def _iast_report_xss(code_string: Text): | ||
increment_iast_span_metric(IAST_SPAN_TAGS.TELEMETRY_EXECUTED_SINK, XSS.vulnerability_type) | ||
_set_metric_iast_executed_sink(XSS.vulnerability_type) | ||
if is_iast_request_enabled(): | ||
if is_pyobject_tainted(code_string): | ||
XSS.report(evidence_value=code_string) |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.