Parse capture groups in if-blocks (fixed for crossplane)#91
Merged
dvershinin merged 1 commit intomasterfrom Dec 6, 2025
Merged
Parse capture groups in if-blocks (fixed for crossplane)#91dvershinin merged 1 commit intomasterfrom
dvershinin merged 1 commit intomasterfrom
Conversation
- Import compile_script to get source variable's boundary - Capture groups from if-block regex now inherit the boundary from the source variable being tested (e.g., $request_uri) - This fixes false positives where capture groups were incorrectly flagged as potentially containing newlines when the source was safe - Fixes #50
7aa134a to
b95bf0f
Compare
|
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.



Based on the work from #51 by @MegaManSec, rebased and adapted for the crossplane-based parser.
This PR enables the
IfBlockto provide variables from regex capture groups when using~,~*,!~, or!~*operators. For example:Key improvement: Capture groups now correctly inherit the boundary (safety constraints) from the source variable being matched. This is critical for HTTP splitting detection:
if ($uri ~* ^/echo/(.*)$)→$1inherits$uri's boundary/[^\x20\t]*→ can contain\r\n→ warning triggeredif ($request_uri ~* ^/echo/(.*)$)→$1inherits$request_uri's boundary/[^\s]*→ cannot contain\r\n→ safeThis distinction matters because:
$uricontains decoded bytes (nginx decodes%0d%0a→ actual\r\n)$request_uricontains raw percent-encoded form (%0d%0astays as-is)Changes:
provide_variables = TruetoIfBlockis_regexproperty to check for regex operatorsvariablesproperty that extracts capture groups from the if condition regex with proper boundary inheritanceFixes #50