fix(aap): use ASGI raw_path for WAF URI evaluation to enable LFI detection on FastAPI#17223
Draft
christophe-papazian wants to merge 5 commits intomainfrom
Draft
fix(aap): use ASGI raw_path for WAF URI evaluation to enable LFI detection on FastAPI#17223christophe-papazian wants to merge 5 commits intomainfrom
christophe-papazian wants to merge 5 commits intomainfrom
Conversation
Codeowners resolved as |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
APPSEC-61974
Description
The ASGI middleware was passing the framework-resolved
scope["path"]asraw_urito the WAF. ASGI frameworks like Starlette/FastAPI resolve path traversal sequences (e.g./waf/../becomes/) inscope["path"]before the middleware sees it. This prevented some URI-based detection rules from triggering on ASGI-based frameworks. The fix usesscope["raw_path"]which preserves the original URI as sent by the client, matching how the WSGI integration already usesRAW_URI.Changes
Production fix (
ddtrace/contrib/internal/asgi/middleware.py):scope["raw_path"]for theraw_uriparameter passed toset_http_meta/ WAF evaluationscope["path"]is still used for thehttp.urlspan tag (user-facing, shows resolved URL)scope["path"]whenraw_pathis not availableTest client fix (
tests/appsec/contrib_appsec/test_fastapi.py):TestClienttransport to inject the original URL path asscope["raw_path"]in the ASGI scopegetattr(client, "_transport", None)for older Starlette/httpx versions that don't expose the transportTest enablement (
tests/appsec/contrib_appsec/utils.py):test_request_suspicious_request_block_match_uri_lfi_transport(raw_path injection not possible)Testing
appsec_threats_fastapi_no_iastsuite (py3.13, fastapi ~0.114.2): 1003 passed, 0 failed_transportavailable)Risks
scope["raw_path"]may not be present in all ASGI servers — the code falls back toscope["path"]whenraw_pathisNone, so there's no regression risk.Additional Notes
RAW_URI/REQUEST_URI(seeddtrace/contrib/internal/wsgi/wsgi.pyline 248). This fix brings ASGI to parity.