Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 22, 2025

Description

Integrates Coraza WAF v2 with Caddy server to provide application-layer security against common web attacks.

Fixes #1724

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Changes

Multi-stage Docker build (frontend/Dockerfile)

  • Added builder stage using xcaddy with github.com/corazawaf/coraza-caddy/v2
  • Custom Caddy binary replaces stock Alpine image
  • Secure WAF data directory (/tmp/coraza/) with 700 permissions

WAF configuration (frontend/coraza.conf)

  • Coraza built-in SQLi and XSS detection operators
  • Custom rules for SQL injection patterns (comments, stored procedures: sp_, xp_, exec)
  • Path traversal protection including double URL-encoding (%252e%252e) and mixed-case variants
  • Blocks 13 sensitive paths: .env, .git, .ssh, .aws, .htaccess, .htpasswd, web.config, admin, config, backup, tmp, logs, wp-admin
  • Security scanner blocking via User-Agent patterns
  • Audit logging to stdout
  • Proper line endings (LF) with final newline per .editorconfig standards

Caddyfile integration (frontend/Caddyfile)

coraza_waf {
    directives `
        Include /etc/caddy/coraza.conf
    `
}

Documentation (README.md)

  • Added WAF to features list and stack description

How Has This Been Tested?

  • No new tests are required
  • Manual tests (description below)

WAF functionality will be validated through existing CI/CD pipeline:

  • Docker image build with custom Caddy
  • E2E tests ensure no functional regression
  • Trivy security scanning

Checklist

  • I have read the CONTRIBUTING doc
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have already been accepted and merged

Further comments

Security rules use defense-in-depth approach:

  1. Coraza's built-in ML-based detection for SQLi/XSS
  2. Pattern-based rules for specific attack vectors
  3. Sensitive path blocking prevents information disclosure

Regex patterns optimized with lazy matching (.*?) and word boundaries (\b) to balance security effectiveness with performance and false positive rates.

All files follow .editorconfig standards with LF line endings and final newlines.

References:

Original prompt

This section details on the original issue you should resolve

<issue_title>Increase Security by adding waf to caddy</issue_title>
<issue_description>
https://github.com/corazawaf/coraza-caddy</issue_description>

<agent_instructions>https://github.com/bcgov/copilot-instructions/blob/main/.github/copilot-upstream.md</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@mishraomp https://medium.com/@jptosso/oss-waf-stack-using-coraza-caddy-and-elastic-3a715dcbf2f2

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Thanks for the PR!

Deployments, as required, will be available below:

Please create PRs in draft mode. Mark as ready to enable:

After merge, new images are deployed in:

Copilot AI and others added 8 commits November 22, 2025 18:51
Co-authored-by: DerekRoberts <4391600+DerekRoberts@users.noreply.github.com>
Co-authored-by: DerekRoberts <4391600+DerekRoberts@users.noreply.github.com>
Co-authored-by: DerekRoberts <4391600+DerekRoberts@users.noreply.github.com>
Co-authored-by: DerekRoberts <4391600+DerekRoberts@users.noreply.github.com>
Co-authored-by: DerekRoberts <4391600+DerekRoberts@users.noreply.github.com>
Co-authored-by: DerekRoberts <4391600+DerekRoberts@users.noreply.github.com>
Co-authored-by: DerekRoberts <4391600+DerekRoberts@users.noreply.github.com>
…nsitive path protection

Co-authored-by: DerekRoberts <4391600+DerekRoberts@users.noreply.github.com>
Copilot AI changed the title [WIP] Increase security by adding WAF to Caddy Add Coraza WAF to Caddy for Enhanced Security Nov 22, 2025
Copilot AI requested a review from DerekRoberts November 22, 2025 19:07
Co-authored-by: DerekRoberts <4391600+DerekRoberts@users.noreply.github.com>
@DerekRoberts DerekRoberts marked this pull request as ready for review December 10, 2025 00:56
Copilot AI review requested due to automatic review settings December 10, 2025 00:56
@DerekRoberts DerekRoberts changed the title Add Coraza WAF to Caddy for Enhanced Security feat: Coraza WAF to Caddy for Enhanced Security Dec 10, 2025
@DerekRoberts DerekRoberts changed the title feat: Coraza WAF to Caddy for Enhanced Security feat: OWASP Coraza WAF for enhanced security Dec 10, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR integrates Coraza WAF v2 with the Caddy server to provide application-layer security against common web attacks including SQL injection, XSS, path traversal, and security scanner detection.

Key Changes:

  • Multi-stage Docker build to compile custom Caddy binary with Coraza WAF plugin
  • Comprehensive WAF rule configuration with SQL injection, XSS, path traversal, and sensitive path protection
  • Updated documentation to reflect the new security feature

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 11 comments.

File Description
frontend/Dockerfile Adds multi-stage build with xcaddy builder to compile Coraza WAF plugin, creates WAF data directories
frontend/coraza.conf New WAF configuration file with security rules for SQL injection, XSS, path traversal, null byte injection, and sensitive path blocking
frontend/Caddyfile Integrates Coraza WAF by including the configuration file in the global directives block
README.md Updates feature list and stack description to mention Coraza WAF integration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Derek Roberts <derek.roberts@gmail.com>
DerekRoberts and others added 6 commits December 9, 2025 17:15
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Derek Roberts <derek.roberts@gmail.com>
- Add 'order coraza_waf first' to Caddyfile global options for proper execution order
- Fix /tmp/coraza directory ownership to UID 1001 for non-root user access
- Update coraza.conf comment to clarify directory creation in Dockerfile
- Add comprehensive WAF documentation section to README.md
- Increase SecRequestBodyNoFilesLimit to 512KB for better API compatibility
- Fix SQL injection regex with word boundaries to reduce false positives
- Remove 'burp' from User-Agent blocking to allow authorized security testing
- Disable SecResponseBodyAccess since no response body rules are configured
- Add documentation comments for SecAuditEngine RelevantOnly behavior
- Update request body limit documentation with clear breakdown
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Fix critical OpenShift UID compatibility: use GID 0 with 770 permissions
- Remove unused response body settings when disabled
- Remove empty XSS comment section
- Renumber rule 1006 to 1005 to fix ID gap
- Fix ReDoS vulnerability in SQL comment regex (/\*[^*]*\*+/)
- Improve SQL comment pattern to match end of string (--(\s|$))
@DerekRoberts DerekRoberts merged commit 75741b6 into main Dec 10, 2025
38 of 40 checks passed
@DerekRoberts DerekRoberts deleted the copilot/add-waf-to-caddy branch December 10, 2025 04:23
@github-project-automation github-project-automation bot moved this from New to Done in DevOps (NR) Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Increase Security by adding waf to caddy

2 participants