Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
97eab11
Add remaining phase4 parser/logging/regression test cases
Easton97-Jens May 3, 2026
25aa9e9
Merge remote-tracking branch 'origin/master' into work
Easton97-Jens May 4, 2026
88d0339
Fix phase4 build issues and raw rule/status logging order
Easton97-Jens May 4, 2026
4d1bb87
Fix phase4 event logging paths and JSON output correctness
Easton97-Jens May 5, 2026
6962d42
Fix phase4 log sanitization, deterministic reasons, and proxy phase4 …
Easton97-Jens May 5, 2026
3e35548
Fix phase4 C-level string safety issues
Easton97-Jens May 5, 2026
440ee43
Merge pull request #6 from Easton97-Jens/codex/implement-phase-4-inte…
Easton97-Jens May 5, 2026
e2ede45
docs: add bilingual phase4 handling and config examples
Easton97-Jens May 6, 2026
2e2c792
Fix json escape alloc safety and phase4 modes log-line assertions
Easton97-Jens May 6, 2026
d73f9ea
Fix phase4-modes test plan count mismatch
Easton97-Jens May 6, 2026
a7bb6e4
docs: expand phase4 guidance and generalize production examples
Easton97-Jens May 6, 2026
4775f32
Fix phase4-modes JSON line assertion for CRLF log lines
Easton97-Jens May 6, 2026
1f37b84
Add diagnostics for failing phase4 modes JSON-line assertion
Easton97-Jens May 6, 2026
0e8720e
Fix MSVC pointer type warning in ngx_file_info call
Easton97-Jens May 7, 2026
be7d24b
Merge pull request #7 from Easton97-Jens/codex/review-nginx-test-conf…
Easton97-Jens May 11, 2026
5c39034
Merge pull request #9 from Easton97-Jens/codex/fix-remaining-issues-i…
Easton97-Jens May 11, 2026
2a31a5b
Refactor phase4 code to address Sonar maintainability issues
Easton97-Jens May 13, 2026
0d3ad62
Flatten processed-chain branch in body filter
Easton97-Jens May 13, 2026
d1b375c
Merge pull request #10 from Easton97-Jens/codex/fix-sonarqube-maintai…
Easton97-Jens May 13, 2026
06f99af
Fix remaining SonarQube issues in body filter
Easton97-Jens May 13, 2026
e35b7fa
Merge pull request #11 from Easton97-Jens/codex/fix-sonarqube-issues-…
Easton97-Jens May 13, 2026
505d4af
Address Copilot review feedback for phase4 handling
Easton97-Jens May 14, 2026
cfc7e22
Fix sanity-check redeclaration and narrow phase4 log capture
Easton97-Jens May 14, 2026
0051975
Rewrite phase4 invalid-config test to use nginx -t output
Easton97-Jens May 14, 2026
329f269
Use repository Test::Nginx harness in phase4 invalid-config test
Easton97-Jens May 14, 2026
8b766e4
Stabilize phase4 invalid-config test nginx -t setup
Easton97-Jens May 14, 2026
beb3e87
Merge pull request #12 from Easton97-Jens/codex/fetch-and-evaluate-co…
Easton97-Jens May 14, 2026
20d7aca
docs: document phase4 nginx directives in README
Easton97-Jens May 14, 2026
3d72b00
Merge pull request #13 from Easton97-Jens/codex/update-readme.md-with…
Easton97-Jens May 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Further information about nginx third-party add-ons support are available [here]
# Usage

ModSecurity for nginx extends your nginx configuration directives.
It adds four new directives and they are:
It adds eight directives and they are:

modsecurity
-----------
Expand Down Expand Up @@ -175,6 +175,31 @@ using the same unique identificator.

String can contain variables.


modsecurity_phase4_mode
------------------------
**syntax:** *modsecurity_phase4_mode minimal | safe | strict*

**context:** *http, server, location*

Controls how phase 4 interventions are handled when response headers were already sent.

modsecurity_phase4_content_types_file
--------------------------------------
**syntax:** *modsecurity_phase4_content_types_file <path>*

**context:** *http, server, location*

Loads the list of response content types that are in scope for phase 4 handling from a file.

modsecurity_phase4_log
----------------------
**syntax:** *modsecurity_phase4_log <path>*

**context:** *http, server, location*

Sets the file used for phase 4 JSON event logging.

modsecurity_use_error_log
-----------
**syntax:** *modsecurity_use_error_log on | off*
Expand Down
16 changes: 16 additions & 0 deletions docs/examples/phase4-content-types.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# phase4-content-types.conf
#
# Format rules:
# 1) Exactly one MIME type per line.
# 2) Lines starting with # are comments.
# 3) Wildcards are not supported (e.g. text/* is invalid).
# 4) Parameters (e.g. "; charset=utf-8") do not need separate entries.
# The module normalizes response Content-Type and compares the base type.
# 5) Keep this list focused on body types you actually want to scope.

text/html
text/plain
application/json
application/problem+json
application/xml
application/xhtml+xml
31 changes: 31 additions & 0 deletions docs/examples/phase4-minimal.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Production example: phase-4 mode "minimal"
# Use when response continuity is more important than forced connection aborts
# for late phase:4 interventions (after headers were already sent).

http {
upstream app_backend {
server 127.0.0.1:8081;
}

server {
listen 80;
server_name example.local;

modsecurity on;
modsecurity_phase4_mode minimal;
modsecurity_phase4_log /var/log/nginx/modsecurity-phase4.log;
modsecurity_phase4_content_types_file /etc/modsecurity/phase4-content-types.conf;

# Inline rule sample for demonstration.
# In production, you can keep using modsecurity_rules_file as usual.
modsecurity_rules '
SecRuleEngine On
SecResponseBodyAccess On
SecRule RESPONSE_BODY "@rx sensitive-marker" "id:940101,phase:4,deny,log,status:403"
';

location / {
proxy_pass http://app_backend;
}
}
}
29 changes: 29 additions & 0 deletions docs/examples/phase4-safe.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Production example: phase-4 mode "safe"
# Default mode in this module. Recommended baseline if you need phase:4
# visibility while avoiding forced disconnects on late interventions.

http {
upstream app_backend {
server 127.0.0.1:8081;
}

server {
listen 80;
server_name example.local;

modsecurity on;
modsecurity_phase4_mode safe;
modsecurity_phase4_log /var/log/nginx/modsecurity-phase4.log;
modsecurity_phase4_content_types_file /etc/modsecurity/phase4-content-types.conf;

modsecurity_rules '
SecRuleEngine On
SecResponseBodyAccess On
SecRule RESPONSE_BODY "@rx sensitive-marker" "id:940102,phase:4,deny,log,status:403"
';

location / {
proxy_pass http://app_backend;
}
}
}
29 changes: 29 additions & 0 deletions docs/examples/phase4-strict.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Production example: phase-4 mode "strict"
# Use only if connection aborts are operationally acceptable, because
# late phase:4 interventions may terminate the connection.

http {
upstream app_backend {
server 127.0.0.1:8081;
}

server {
listen 80;
server_name example.local;

modsecurity on;
modsecurity_phase4_mode strict;
modsecurity_phase4_log /var/log/nginx/modsecurity-phase4.log;
modsecurity_phase4_content_types_file /etc/modsecurity/phase4-content-types.conf;

modsecurity_rules '
SecRuleEngine On
SecResponseBodyAccess On
SecRule RESPONSE_BODY "@rx sensitive-marker" "id:940103,phase:4,deny,log,status:403"
';

location / {
proxy_pass http://app_backend;
}
}
}
Loading
Loading