Skip to content

Fix Apache RewriteCond negation for string and integer comparisons - #70556

Open
joshbarros wants to merge 1 commit into
dotnet:mainfrom
joshbarros:fix/70505-rewritecond-negation
Open

joshbarros wants to merge 1 commit into
dotnet:mainfrom
joshbarros:fix/70505-rewritecond-negation

Conversation

@joshbarros

Copy link
Copy Markdown
  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making.

Description

A leading ! in an Apache RewriteCond comparison was not negating the result:

  • For string comparisons (!=https), RuleBuilder.AddConditionFromParts passed the parsed Invert flag as StringMatch's ignoreCase argument, so the pattern matched case-insensitively instead of negating.
  • For integer comparisons (!-eq1), the Invert flag was dropped entirely.

This adds a negate parameter to StringMatch and IntegerMatch and inverts the comparison result, following the existing RegexMatch/IsFileMatch convention. StringMatch now also honors the [NC] flag for case-insensitivity, which was previously ignored for string comparisons.

Validation

  • Invoke_RewriteCondNegationIsApplied covers !=https, =https and !-eq1 (both matching and non-matching query values).
  • Added negate cases to StringMatchTests and IntegerMatchTests.
  • dotnet test src/Middleware/Rewrite/test/Microsoft.AspNetCore.Rewrite.Tests.csproj: 488 passed, 0 failed.

Fixes #70505

RuleBuilder passed the parsed Invert flag as StringMatch's ignoreCase argument and omitted it from IntegerMatch, so a leading '!' in a RewriteCond comparison was treated as case-insensitivity (strings) or ignored (integers) instead of negating the result.

Add a negate parameter to StringMatch and IntegerMatch and invert the comparison result, following the existing RegexMatch/IsFileMatch convention. StringMatch now also honors the [NC] flag for case-insensitivity.

Fix dotnet#70505
@github-actions github-actions Bot added the area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares label Nov 13, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 13, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @joshbarros. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@PureWeen

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source-only review of frozen head f01b1e2b9f04942a5f12c901a4b78ce71d4ec0df.

The cross-cutting guide completed its in-scope review. The only proposed candidate—nonnumeric input under a negated integer comparison—was independently verified and discarded because the exact input follows the same early-failure path at merge base 59835e6087e90b972a905dc303523cfbb5d828ef and at the frozen head. It is surfaced inline with its discarded disposition as required by the review protocol.

Existing feedback contained no source-supported duplicate finding. No unresolved candidates remain. Changed tests were assessed from source: the new middleware cases exercise the parser and middleware path and would fail with the fix reverted; unit coverage does not include nonnumeric integer inputs, but that omission does not establish a regression.

Guide completion: docs/CrossCuttingGuidance.md complete for applicable source checks. Security assessment and execution of code, tests, CI, browser workflows, and samples were excluded by the frozen bundle policy. No materially changed area lacked a routed specialist guide.

Provenance: complete version-2 trusted bundle; guidance from immutable commit 59835e6087e90b972a905dc303523cfbb5d828ef; per-guide worker and candidate verifier both ran with gpt-5.6-sol and runtime-default reasoning effort. Proof is source-only. Tracked Git bytes only; symlink, submodule, and LFS targets cannot establish behavior, and no runtime validation was performed.

Generated by ASP.NET Core Pull Request Review for #70556 · copilot · gpt56 · 98.4 AIC · ⌖ 12.5 AIC · ⊞ 18.8K
Comment /review to run again

@joshbarros

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apache RewriteCond negation is incorrectly applied to string and integer comparisons

2 participants