Skip to content

Commit c739c60

Browse files
fix(iast): report cookie name [backport 2.4] (#7951)
Backport ccfc0ab from #7927 to 2.4. ## 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 c6c480c commit c739c60

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
@@ -20,9 +20,9 @@ def test_insecure_cookies(iast_span_defaults):
2020
assert VULN_INSECURE_COOKIE in vulnerabilities_types
2121
assert VULN_NO_SAMESITE_COOKIE in vulnerabilities_types
2222

23-
assert vulnerabilities[0].evidence.value == "foo=bar"
24-
assert vulnerabilities[1].evidence.value == "foo=bar"
25-
assert vulnerabilities[2].evidence.value == "foo=bar"
23+
assert vulnerabilities[0].evidence.value == "foo"
24+
assert vulnerabilities[1].evidence.value == "foo"
25+
assert vulnerabilities[2].evidence.value == "foo"
2626

2727
assert vulnerabilities[0].location.line is None
2828
assert vulnerabilities[0].location.path is None
@@ -39,8 +39,8 @@ def test_nohttponly_cookies(iast_span_defaults):
3939
assert VULN_NO_HTTPONLY_COOKIE in vulnerabilities_types
4040
assert VULN_NO_SAMESITE_COOKIE in vulnerabilities_types
4141

42-
assert vulnerabilities[0].evidence.value == "foo=bar;secure"
43-
assert vulnerabilities[1].evidence.value == "foo=bar;secure"
42+
assert vulnerabilities[0].evidence.value == "foo"
43+
assert vulnerabilities[1].evidence.value == "foo"
4444

4545
assert vulnerabilities[0].location.line is None
4646
assert vulnerabilities[0].location.path is None
@@ -61,7 +61,7 @@ def test_nosamesite_cookies_missing(iast_span_defaults):
6161

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

6666

6767
def test_nosamesite_cookies_none(iast_span_defaults):
@@ -74,7 +74,7 @@ def test_nosamesite_cookies_none(iast_span_defaults):
7474
assert len(vulnerabilities) == 1
7575

7676
assert vulnerabilities[0].type == VULN_NO_SAMESITE_COOKIE
77-
assert vulnerabilities[0].evidence.value == "foo=bar;secure;httponly;samesite=none"
77+
assert vulnerabilities[0].evidence.value == "foo"
7878

7979

8080
def test_nosamesite_cookies_other(iast_span_defaults):
@@ -87,7 +87,7 @@ def test_nosamesite_cookies_other(iast_span_defaults):
8787
assert len(vulnerabilities) == 1
8888

8989
assert vulnerabilities[0].type == VULN_NO_SAMESITE_COOKIE
90-
assert vulnerabilities[0].evidence.value == "foo=bar;secure;httponly;samesite=none"
90+
assert vulnerabilities[0].evidence.value == "foo"
9191

9292

9393
def test_nosamesite_cookies_lax_no_error(iast_span_defaults):

0 commit comments

Comments
 (0)