-
Couldn't load subscription status.
- Fork 468
fix(iast): weak hash error if vulnerability is outside the context #15029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(iast): weak hash error if vulnerability is outside the context #15029
Conversation
|
|
Bootstrap import analysisComparison of import times between this PR and base. SummaryThe average import time from this PR is: 234 ± 2 ms. The average import time from base is: 238 ± 2 ms. The import time difference between this PR and base is: -3.26 ± 0.08 ms. Import time breakdownThe following import paths have shrunk:
|
Performance SLOsComparing candidate avara1986/APPSEC-59771-fix-weakhash-exception (48fe450) with baseline main (26c7507) 📈 Performance Regressions (2 suites)📈 iast_aspects - 40/40✅ re_expand_aspectTime: ✅ 32.155µs (SLO: <40.000µs 📉 -19.6%) vs baseline: +1.0% Memory: ✅ 38.103MB (SLO: <39.000MB -2.3%) vs baseline: +4.9% ✅ re_expand_noaspectTime: ✅ 29.995µs (SLO: <40.000µs 📉 -25.0%) vs baseline: +3.0% Memory: ✅ 38.122MB (SLO: <39.000MB -2.3%) vs baseline: +4.9% ✅ re_findall_aspectTime: ✅ 2.908µs (SLO: <10.000µs 📉 -70.9%) vs baseline: +0.2% Memory: ✅ 38.142MB (SLO: <39.000MB -2.2%) vs baseline: +5.0% ✅ re_findall_noaspectTime: ✅ 1.423µs (SLO: <10.000µs 📉 -85.8%) vs baseline: +1.5% Memory: ✅ 38.063MB (SLO: <39.000MB -2.4%) vs baseline: +4.7% ✅ re_finditer_aspectTime: ✅ 4.709µs (SLO: <10.000µs 📉 -52.9%) vs baseline: +5.7% Memory: ✅ 38.103MB (SLO: <39.000MB -2.3%) vs baseline: +4.9% ✅ re_finditer_noaspectTime: ✅ 1.415µs (SLO: <10.000µs 📉 -85.8%) vs baseline: -0.5% Memory: ✅ 38.103MB (SLO: <39.000MB -2.3%) vs baseline: +4.9% ✅ re_fullmatch_aspectTime: ✅ 2.642µs (SLO: <10.000µs 📉 -73.6%) vs baseline: -0.5% Memory: ✅ 38.122MB (SLO: <39.000MB -2.3%) vs baseline: +4.9% ✅ re_fullmatch_noaspectTime: ✅ 1.293µs (SLO: <10.000µs 📉 -87.1%) vs baseline: +0.3% Memory: ✅ 38.103MB (SLO: <39.000MB -2.3%) vs baseline: +4.8% ✅ re_group_aspectTime: ✅ 2.958µs (SLO: <10.000µs 📉 -70.4%) vs baseline: +1.2% Memory: ✅ 38.063MB (SLO: <39.000MB -2.4%) vs baseline: +4.7% ✅ re_group_noaspectTime: ✅ 1.586µs (SLO: <10.000µs 📉 -84.1%) vs baseline: -1.1% Memory: ✅ 38.122MB (SLO: <39.000MB -2.3%) vs baseline: +4.9% ✅ re_groups_aspectTime: ✅ 3.325µs (SLO: <10.000µs 📉 -66.8%) vs baseline: +9.1% Memory: ✅ 38.103MB (SLO: <39.000MB -2.3%) vs baseline: +4.9% ✅ re_groups_noaspectTime: ✅ 1.703µs (SLO: <10.000µs 📉 -83.0%) vs baseline: -0.5% Memory: ✅ 38.103MB (SLO: <39.000MB -2.3%) vs baseline: +4.8% ✅ re_match_aspectTime: ✅ 2.979µs (SLO: <10.000µs 📉 -70.2%) vs baseline: 📈 +10.6% Memory: ✅ 38.122MB (SLO: <39.000MB -2.3%) vs baseline: +4.9% ✅ re_match_noaspectTime: ✅ 1.292µs (SLO: <10.000µs 📉 -87.1%) vs baseline: -0.3% Memory: ✅ 38.122MB (SLO: <39.000MB -2.3%) vs baseline: +5.1% ✅ re_search_aspectTime: ✅ 2.563µs (SLO: <10.000µs 📉 -74.4%) vs baseline: -0.7% Memory: ✅ 38.044MB (SLO: <39.000MB -2.5%) vs baseline: +4.7% ✅ re_search_noaspectTime: ✅ 1.197µs (SLO: <10.000µs 📉 -88.0%) vs baseline: +0.6% Memory: ✅ 38.083MB (SLO: <39.000MB -2.4%) vs baseline: +4.7% ✅ re_sub_aspectTime: ✅ 3.407µs (SLO: <10.000µs 📉 -65.9%) vs baseline: ~same Memory: ✅ 38.142MB (SLO: <39.000MB -2.2%) vs baseline: +4.9% ✅ re_sub_noaspectTime: ✅ 1.530µs (SLO: <10.000µs 📉 -84.7%) vs baseline: -0.2% Memory: ✅ 38.122MB (SLO: <39.000MB -2.3%) vs baseline: +4.9% ✅ re_subn_aspectTime: ✅ 3.706µs (SLO: <10.000µs 📉 -62.9%) vs baseline: +0.7% Memory: ✅ 38.142MB (SLO: <39.000MB -2.2%) vs baseline: +5.0% ✅ re_subn_noaspectTime: ✅ 1.612µs (SLO: <10.000µs 📉 -83.9%) vs baseline: -0.9% Memory: ✅ 38.044MB (SLO: <39.000MB -2.5%) vs baseline: +4.8% 📈 telemetryaddmetric - 30/30✅ 1-count-metric-1-timesTime: ✅ 3.276µs (SLO: <20.000µs 📉 -83.6%) vs baseline: 📈 +10.5% Memory: ✅ 32.204MB (SLO: <34.000MB -5.3%) vs baseline: +4.9% ✅ 1-count-metrics-100-timesTime: ✅ 201.522µs (SLO: <220.000µs -8.4%) vs baseline: +0.7% Memory: ✅ 32.204MB (SLO: <34.000MB -5.3%) vs baseline: +4.9% ✅ 1-distribution-metric-1-timesTime: ✅ 3.356µs (SLO: <20.000µs 📉 -83.2%) vs baseline: +2.7% Memory: ✅ 32.185MB (SLO: <34.000MB -5.3%) vs baseline: +4.9% ✅ 1-distribution-metrics-100-timesTime: ✅ 214.072µs (SLO: <220.000µs -2.7%) vs baseline: +0.1% Memory: ✅ 32.224MB (SLO: <34.000MB -5.2%) vs baseline: +5.0% ✅ 1-gauge-metric-1-timesTime: ✅ 2.175µs (SLO: <20.000µs 📉 -89.1%) vs baseline: +0.4% Memory: ✅ 32.204MB (SLO: <34.000MB -5.3%) vs baseline: +4.9% ✅ 1-gauge-metrics-100-timesTime: ✅ 138.910µs (SLO: <150.000µs -7.4%) vs baseline: +1.3% Memory: ✅ 32.224MB (SLO: <34.000MB -5.2%) vs baseline: +5.0% ✅ 1-rate-metric-1-timesTime: ✅ 3.197µs (SLO: <20.000µs 📉 -84.0%) vs baseline: +4.2% Memory: ✅ 32.224MB (SLO: <34.000MB -5.2%) vs baseline: +4.9% ✅ 1-rate-metrics-100-timesTime: ✅ 214.616µs (SLO: <250.000µs 📉 -14.2%) vs baseline: +1.4% Memory: ✅ 32.204MB (SLO: <34.000MB -5.3%) vs baseline: +4.9% ✅ 100-count-metrics-100-timesTime: ✅ 20.272ms (SLO: <22.000ms -7.9%) vs baseline: +1.4% Memory: ✅ 32.165MB (SLO: <34.000MB -5.4%) vs baseline: +4.9% ✅ 100-distribution-metrics-100-timesTime: ✅ 2.278ms (SLO: <2.300ms 🟡 -1.0%) vs baseline: +2.8% Memory: ✅ 32.165MB (SLO: <34.000MB -5.4%) vs baseline: +4.7% ✅ 100-gauge-metrics-100-timesTime: ✅ 1.402ms (SLO: <1.550ms -9.6%) vs baseline: ~same Memory: ✅ 32.204MB (SLO: <34.000MB -5.3%) vs baseline: +4.9% ✅ 100-rate-metrics-100-timesTime: ✅ 2.209ms (SLO: <2.550ms 📉 -13.4%) vs baseline: +1.7% Memory: ✅ 32.204MB (SLO: <34.000MB -5.3%) vs baseline: +4.9% ✅ flush-1-metricTime: ✅ 4.781µs (SLO: <20.000µs 📉 -76.1%) vs baseline: +2.0% Memory: ✅ 32.185MB (SLO: <34.000MB -5.3%) vs baseline: +4.9% ✅ flush-100-metricsTime: ✅ 174.107µs (SLO: <250.000µs 📉 -30.4%) vs baseline: -1.1% Memory: ✅ 32.185MB (SLO: <34.000MB -5.3%) vs baseline: +4.7% ✅ flush-1000-metricsTime: ✅ 2.118ms (SLO: <2.500ms 📉 -15.3%) vs baseline: -0.6% Memory: ✅ 33.010MB (SLO: <34.500MB -4.3%) vs baseline: +4.9% 🟡 Near SLO Breach (5 suites)🟡 djangosimple - 30/30✅ appsecTime: ✅ 20.525ms (SLO: <22.300ms -8.0%) vs baseline: +0.2% Memory: ✅ 65.254MB (SLO: <67.000MB -2.6%) vs baseline: +4.8% ✅ exception-replay-enabledTime: ✅ 1.346ms (SLO: <1.450ms -7.2%) vs baseline: +0.3% Memory: ✅ 64.693MB (SLO: <67.000MB -3.4%) vs baseline: +4.9% ✅ iastTime: ✅ 20.566ms (SLO: <22.250ms -7.6%) vs baseline: +0.3% Memory: ✅ 65.233MB (SLO: <67.000MB -2.6%) vs baseline: +4.8% ✅ profilerTime: ✅ 15.547ms (SLO: <16.550ms -6.1%) vs baseline: -0.2% Memory: ✅ 54.162MB (SLO: <54.500MB 🟡 -0.6%) vs baseline: +5.0% ✅ resource-renamingTime: ✅ 20.572ms (SLO: <21.750ms -5.4%) vs baseline: -0.3% Memory: ✅ 65.293MB (SLO: <67.000MB -2.5%) vs baseline: +4.9% ✅ span-code-originTime: ✅ 25.399ms (SLO: <28.200ms -9.9%) vs baseline: -0.3% Memory: ✅ 67.303MB (SLO: <69.500MB -3.2%) vs baseline: +4.5% ✅ tracerTime: ✅ 20.525ms (SLO: <21.750ms -5.6%) vs baseline: +0.3% Memory: ✅ 65.333MB (SLO: <67.000MB -2.5%) vs baseline: +5.0% ✅ tracer-and-profilerTime: ✅ 22.626ms (SLO: <23.500ms -3.7%) vs baseline: -0.4% Memory: ✅ 66.864MB (SLO: <67.500MB 🟡 -0.9%) vs baseline: +5.1% ✅ tracer-dont-create-db-spansTime: ✅ 19.358ms (SLO: <21.500ms -10.0%) vs baseline: ~same Memory: ✅ 65.252MB (SLO: <66.000MB 🟡 -1.1%) vs baseline: +4.8% ✅ tracer-minimalTime: ✅ 16.589ms (SLO: <17.500ms -5.2%) vs baseline: -0.5% Memory: ✅ 65.234MB (SLO: <66.000MB 🟡 -1.2%) vs baseline: +4.7% ✅ tracer-nativeTime: ✅ 20.514ms (SLO: <21.750ms -5.7%) vs baseline: -0.2% Memory: ✅ 71.280MB (SLO: <72.500MB 🟡 -1.7%) vs baseline: +4.8% ✅ tracer-no-cachesTime: ✅ 18.470ms (SLO: <19.650ms -6.0%) vs baseline: -0.2% Memory: ✅ 65.312MB (SLO: <67.000MB -2.5%) vs baseline: +5.0% ✅ tracer-no-databasesTime: ✅ 18.752ms (SLO: <20.100ms -6.7%) vs baseline: ~same Memory: ✅ 65.293MB (SLO: <67.000MB -2.5%) vs baseline: +4.8% ✅ tracer-no-middlewareTime: ✅ 20.247ms (SLO: <21.500ms -5.8%) vs baseline: +0.2% Memory: ✅ 65.263MB (SLO: <67.000MB -2.6%) vs baseline: +4.9% ✅ tracer-no-templatesTime: ✅ 20.405ms (SLO: <22.000ms -7.3%) vs baseline: +0.4% Memory: ✅ 65.236MB (SLO: <67.000MB -2.6%) vs baseline: +4.8% 🟡 errortrackingdjangosimple - 6/6✅ errortracking-enabled-allTime: ✅ 18.059ms (SLO: <19.850ms -9.0%) vs baseline: -0.4% Memory: ✅ 65.204MB (SLO: <66.500MB 🟡 -1.9%) vs baseline: +4.8% ✅ errortracking-enabled-userTime: ✅ 18.112ms (SLO: <19.400ms -6.6%) vs baseline: +0.3% Memory: ✅ 65.263MB (SLO: <66.500MB 🟡 -1.9%) vs baseline: +4.9% ✅ tracer-enabledTime: ✅ 18.043ms (SLO: <19.450ms -7.2%) vs baseline: -0.1% Memory: ✅ 65.214MB (SLO: <66.500MB 🟡 -1.9%) vs baseline: +4.8% 🟡 errortrackingflasksqli - 6/6✅ errortracking-enabled-allTime: ✅ 2.070ms (SLO: <2.300ms -10.0%) vs baseline: +0.1% Memory: ✅ 52.062MB (SLO: <53.500MB -2.7%) vs baseline: +4.5% ✅ errortracking-enabled-userTime: ✅ 2.073ms (SLO: <2.250ms -7.9%) vs baseline: ~same Memory: ✅ 52.101MB (SLO: <53.500MB -2.6%) vs baseline: +4.6% ✅ tracer-enabledTime: ✅ 2.070ms (SLO: <2.300ms 📉 -10.0%) vs baseline: +0.1% Memory: ✅ 52.514MB (SLO: <53.500MB 🟡 -1.8%) vs baseline: +5.3% 🟡 flasksimple - 18/18✅ appsec-getTime: ✅ 4.597ms (SLO: <4.750ms -3.2%) vs baseline: ~same Memory: ✅ 61.971MB (SLO: <65.000MB -4.7%) vs baseline: +4.9% ✅ appsec-postTime: ✅ 6.651ms (SLO: <6.750ms 🟡 -1.5%) vs baseline: +0.4% Memory: ✅ 61.971MB (SLO: <65.000MB -4.7%) vs baseline: +5.0% ✅ appsec-telemetryTime: ✅ 4.587ms (SLO: <4.750ms -3.4%) vs baseline: ~same Memory: ✅ 61.892MB (SLO: <65.000MB -4.8%) vs baseline: +4.7% ✅ debuggerTime: ✅ 1.856ms (SLO: <2.000ms -7.2%) vs baseline: -0.1% Memory: ✅ 45.318MB (SLO: <47.000MB -3.6%) vs baseline: +4.3% ✅ iast-getTime: ✅ 1.857ms (SLO: <2.000ms -7.2%) vs baseline: +0.2% Memory: ✅ 42.448MB (SLO: <49.000MB 📉 -13.4%) vs baseline: +4.8% ✅ profilerTime: ✅ 1.910ms (SLO: <2.100ms -9.1%) vs baseline: ~same Memory: ✅ 46.478MB (SLO: <47.000MB 🟡 -1.1%) vs baseline: +4.0% ✅ resource-renamingTime: ✅ 3.375ms (SLO: <3.650ms -7.5%) vs baseline: +0.1% Memory: ✅ 52.258MB (SLO: <53.500MB -2.3%) vs baseline: +4.9% ✅ tracerTime: ✅ 3.361ms (SLO: <3.650ms -7.9%) vs baseline: +0.2% Memory: ✅ 52.258MB (SLO: <53.500MB -2.3%) vs baseline: +4.9% ✅ tracer-nativeTime: ✅ 3.365ms (SLO: <3.650ms -7.8%) vs baseline: +0.3% Memory: ✅ 58.203MB (SLO: <60.000MB -3.0%) vs baseline: +5.0% 🟡 flasksqli - 6/6✅ appsec-enabledTime: ✅ 3.972ms (SLO: <4.200ms -5.4%) vs baseline: +0.3% Memory: ✅ 62.226MB (SLO: <66.000MB -5.7%) vs baseline: +5.1% ✅ iast-enabledTime: ✅ 2.444ms (SLO: <2.800ms 📉 -12.7%) vs baseline: -0.2% Memory: ✅ 58.845MB (SLO: <60.000MB 🟡 -1.9%) vs baseline: +4.6% ✅ tracer-enabledTime: ✅ 2.064ms (SLO: <2.250ms -8.3%) vs baseline: -0.3% Memory: ✅ 52.219MB (SLO: <54.500MB -4.2%) vs baseline: +4.7%
|
…15029) ## Description This PR addresses an issue where using weak hashing or cipher algorithms outside of a request context (e.g., during application startup) could raise an unhandled exception. The fix ensures proper error handling when IAST operations are performed without an active request context. ### Root Cause The issue occurred in the [has_quota](cci:1://file:///home/alberto.vara/projects/dd-python/dd-trace-py/ddtrace/appsec/_iast/taint_sinks/_base.py:7:4-12:20) method of the vulnerability base class, which was not properly handling cases where there was no active request context. When IAST operations were performed outside of a request (e.g., during application startup or in unsupported frameworks), the code would attempt to access the vulnerability budget from a non-existent context, leading to an unhandled exception. ### Changes 1. Added null check for IAST context in [has_quota](cci:1://file:///home/alberto.vara/projects/dd-python/dd-trace-py/ddtrace/appsec/_iast/taint_sinks/_base.py:7:4-12:20) method to safely handle cases with no active request 2. Return `False` when no context is available, preventing further processing of vulnerabilities 3. Added test cases to verify the fix works in various scenarios 4. Updated the release notes to document the fix (cherry picked from commit 8940186)
…ackport 3.17] (#15038) Backport 8940186 from #15029 to 3.17. ## Description This PR addresses an issue where using weak hashing or cipher algorithms outside of a request context (e.g., during application startup) could raise an unhandled exception. The fix ensures proper error handling when IAST operations are performed without an active request context. ### Root Cause The issue occurred in the [has_quota](cci:1://file:///home/alberto.vara/projects/dd-python/dd-trace-py/ddtrace/appsec/_iast/taint_sinks/_base.py:7:4-12:20) method of the vulnerability base class, which was not properly handling cases where there was no active request context. When IAST operations were performed outside of a request (e.g., during application startup or in unsupported frameworks), the code would attempt to access the vulnerability budget from a non-existent context, leading to an unhandled exception. ### Changes 1. Added null check for IAST context in [has_quota](cci:1://file:///home/alberto.vara/projects/dd-python/dd-trace-py/ddtrace/appsec/_iast/taint_sinks/_base.py:7:4-12:20) method to safely handle cases with no active request 2. Return `False` when no context is available, preventing further processing of vulnerabilities 3. Added test cases to verify the fix works in various scenarios 4. Updated the release notes to document the fix Co-authored-by: Alberto Vara <[email protected]>
Description
This PR addresses an issue where using weak hashing or cipher algorithms outside of a request context (e.g., during application startup) could raise an unhandled exception. The fix ensures proper error handling when IAST operations are performed without an active request context.
Root Cause
The issue occurred in the has_quota method of the vulnerability base class, which was not properly handling cases where there was no active request context. When IAST operations were performed outside of a request (e.g., during application startup or in unsupported frameworks), the code would attempt to access the vulnerability budget from a non-existent context, leading to an unhandled exception.
Changes
Falsewhen no context is available, preventing further processing of vulnerabilities