Skip to content

Commit fa94841

Browse files
fix(iast): report cookie name [backport 2.3] (#7929)
Backport ccfc0ab from #7927 to 2.3. ## Description Ensure that Cookies vulnerabilities report only the cookie name ## 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] 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)) ## Reviewer Checklist - [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]>
1 parent 3f93320 commit fa94841

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

ddtrace/appsec/_iast/taint_sinks/insecure_cookie.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,16 @@ def asm_check_cookies(cookies): # type: (Optional[Dict[str, str]]) -> None
4646

4747
for cookie_key, cookie_value in six.iteritems(cookies):
4848
lvalue = cookie_value.lower().replace(" ", "")
49-
evidence = "%s=%s" % (cookie_key, cookie_value)
5049

5150
if ";secure" not in lvalue:
5251
increment_iast_span_metric(IAST_SPAN_TAGS.TELEMETRY_EXECUTED_SINK, InsecureCookie.vulnerability_type)
5352
_set_metric_iast_executed_sink(InsecureCookie.vulnerability_type)
54-
InsecureCookie.report(evidence_value=evidence)
53+
InsecureCookie.report(evidence_value=cookie_key)
5554

5655
if ";httponly" not in lvalue:
5756
increment_iast_span_metric(IAST_SPAN_TAGS.TELEMETRY_EXECUTED_SINK, NoHttpOnlyCookie.vulnerability_type)
5857
_set_metric_iast_executed_sink(NoHttpOnlyCookie.vulnerability_type)
59-
NoHttpOnlyCookie.report(evidence_value=evidence)
58+
NoHttpOnlyCookie.report(evidence_value=cookie_key)
6059

6160
if ";samesite=" in lvalue:
6261
ss_tokens = lvalue.split(";samesite=")
@@ -72,4 +71,4 @@ def asm_check_cookies(cookies): # type: (Optional[Dict[str, str]]) -> None
7271
if report_samesite:
7372
increment_iast_span_metric(IAST_SPAN_TAGS.TELEMETRY_EXECUTED_SINK, NoSameSite.vulnerability_type)
7473
_set_metric_iast_executed_sink(NoSameSite.vulnerability_type)
75-
NoSameSite.report(evidence_value=evidence)
74+
NoSameSite.report(evidence_value=cookie_key)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Vulnerability Management for Code-level (IAST): Ensure that Cookies vulnerabilities report only the cookie name.

tests/appsec/iast/taint_sinks/test_insecure_cookie.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def test_insecure_cookies(iast_span_defaults):
2222
assert VULN_INSECURE_COOKIE in vulnerabilities_types
2323
assert VULN_NO_SAMESITE_COOKIE in vulnerabilities_types
2424

25-
assert vulnerabilities[0].evidence.value == "foo=bar"
26-
assert vulnerabilities[1].evidence.value == "foo=bar"
27-
assert vulnerabilities[2].evidence.value == "foo=bar"
25+
assert vulnerabilities[0].evidence.value == "foo"
26+
assert vulnerabilities[1].evidence.value == "foo"
27+
assert vulnerabilities[2].evidence.value == "foo"
2828

2929
assert vulnerabilities[0].location.line is None
3030
assert vulnerabilities[0].location.path is None
@@ -42,8 +42,8 @@ def test_nohttponly_cookies(iast_span_defaults):
4242
assert VULN_NO_HTTPONLY_COOKIE in vulnerabilities_types
4343
assert VULN_NO_SAMESITE_COOKIE in vulnerabilities_types
4444

45-
assert vulnerabilities[0].evidence.value == "foo=bar;secure"
46-
assert vulnerabilities[1].evidence.value == "foo=bar;secure"
45+
assert vulnerabilities[0].evidence.value == "foo"
46+
assert vulnerabilities[1].evidence.value == "foo"
4747

4848
assert vulnerabilities[0].location.line is None
4949
assert vulnerabilities[0].location.path is None
@@ -64,7 +64,7 @@ def test_nosamesite_cookies_missing(iast_span_defaults):
6464

6565
assert len(vulnerabilities) == 1
6666
assert vulnerabilities[0].type == VULN_NO_SAMESITE_COOKIE
67-
assert vulnerabilities[0].evidence.value == "foo=bar;secure;httponly"
67+
assert vulnerabilities[0].evidence.value == "foo"
6868

6969

7070
def test_nosamesite_cookies_none(iast_span_defaults):
@@ -77,7 +77,7 @@ def test_nosamesite_cookies_none(iast_span_defaults):
7777
assert len(vulnerabilities) == 1
7878

7979
assert vulnerabilities[0].type == VULN_NO_SAMESITE_COOKIE
80-
assert vulnerabilities[0].evidence.value == "foo=bar;secure;httponly;samesite=none"
80+
assert vulnerabilities[0].evidence.value == "foo"
8181

8282

8383
def test_nosamesite_cookies_other(iast_span_defaults):
@@ -90,7 +90,7 @@ def test_nosamesite_cookies_other(iast_span_defaults):
9090
assert len(vulnerabilities) == 1
9191

9292
assert vulnerabilities[0].type == VULN_NO_SAMESITE_COOKIE
93-
assert vulnerabilities[0].evidence.value == "foo=bar;secure;httponly;samesite=none"
93+
assert vulnerabilities[0].evidence.value == "foo"
9494

9595

9696
def test_nosamesite_cookies_lax_no_error(iast_span_defaults):

0 commit comments

Comments
 (0)