Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Feature Request: Wildcard/pattern support in ctl:ruleRemoveTargetById (v3)

オープン
#3,505 コメント 7 件 リアクション 2 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
cpp
領域
security

調査の方向性

まず src/actions/ctl/rule_remove_target_by_id.cc と src/rule_with_operator.cc を読み、init()、getFinalVars、評価ループに注目してください。Utils::Regex がどのように使われているか、またトランザクション状態が除外をどのように保持しているかを確認してください。リテラルのターゲットが引き続き機能し、有効なパターンが実行時に変数名とマッチし、無効な正規表現が設定中に失敗し、提示された ReDoS の制限に対処できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

3.x

Hi team! This is my first ask/contribution to ModSecurity. I'm hoping to help improve false positive management for folks using CRS — please let me know if I can clarify anything or adjust this proposal.

Is your feature request related to a problem? Please describe.

Currently, ctl:ruleRemoveTargetById only allows excluding a Core Rule Set (CRS) rule from inspecting a literal, exact variable name (e.g., ARGS:json.JobDescription). It does not support wildcards or regular expressions.

This creates a significant pain point for modern APIs accepting JSON arrays or GraphQL payloads, where keys are dynamic:

  • Payload: [{"JobDescription": "..."}, {"JobDescription": "..."}, ...]
  • Variables: ARGS:json.0.JobDescription, ARGS:json.1.JobDescription, …

Excluding these requires listing every possible index, which is impractical and leads to users disabling rules entirely or losing protection for the whole endpoint via path exclusions.

Note: This request is related to the legacy v2 PR #3121 and Issue #911, but focuses specifically on a v3 implementation.

Describe the solution you'd like

Extend ctl:ruleRemoveTargetById to accept a pattern (regex) that matches variable names, mirroring the existing regex support in SecRuleUpdateTargetById, but enabling runtime/URI-scoped use.

Example Syntax:

SecRule REQUEST_URI "@beginsWith /api/jobs" \
    "id:100100,phase:1,pass,nolog,ctl:ruleRemoveTargetById=932125;ARGS:/^json\.\d+\.JobDescription$/"

Expected Behavior: When the target rule inspects variables, any variable whose name matches the compiled pattern is excluded. Literal targets must continue to work unchanged. Invalid regex should fail at config load.

Describe alternatives you've considered

  1. Path/method exclusion: Loses protection for the entire endpoint.
  2. SecRuleUpdateTargetById: Applies globally at configure-time, which is risky if other endpoints share the same JSON structure.

Technical Feasibility & Security Considerations (v3)

The change is feasible in v3 with localized edits, as the engine already utilizes Utils::Regex (PCRE2) for variable matching.

  • src/actions/ctl/rule_remove_target_by_id.cc: In init(), detect the COLLECTION:/.../ pattern. If it's a regex, compile via Utils::Regex and push to the transaction state.
  • src/rule_with_operator.cc: In getFinalVars and the evaluate loop, check exclusions against regex targets using m_regex->searchAll(varName).size() > 0.

ReDoS Mitigations Risks:
Because the variable name (e.g., JSON key) is user-controlled, strict limits are required to prevent ReDoS via the ctl evaluation:

  1. Subject Length Limit: Cap the evaluated string (variable name) at 256 characters. If exceeded, skip the regex match (fail closed/evaluate the rule).
  2. Match Limits: Utilize pcre2_set_match_limit() for this specific code path.
  3. Compile-time validation: Reject known ReDoS patterns at config load.
主要言語
C++
スター
9.8k
フォーク
1.8k
平均マージ
2時間 46分
マージ済み PR(30日)
1

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

owasp-modsecurity/ModSecurity のほかの issue

owasp-modsecurity/ModSecurity の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。