Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

modsecurity-snippet annotation is not validated in webhook validator #14604

@angelbarrera92

Description

@angelbarrera92

What happened:

The modsecurity-snippet annotation is not being validated at webhook admission time. This allows invalid ModSecurity rules to be deployed without any validation or error feedback.

What you expected to happen:

Invalid ModSecurity rules in the modsecurity-snippet annotation should be caught at admission time using the modsec-rules-check CLI tool. Users should receive clear feedback about validation failures, either as:

  • A warning in non-strict mode (default): Invalid rules are logged as warnings but deployment proceeds
  • A rejection in strict mode: Invalid rules cause the Ingress admission to be denied

NGINX Ingress controller version (exec into the pod and run /nginx-ingress-controller --version):

-------------------------------------------------------------------------------
NGINX Ingress controller
  Release:       v1.14.3
  Build:         b4ab41015421ae27f3a96d73f013183b7e166735
  Repository:    https://github.com/kubernetes/ingress-nginx
  nginx version: nginx/1.27.1

-------------------------------------------------------------------------------

Kubernetes version (use kubectl version):

Client Version: v1.34.3
Kustomize Version: v5.7.1
Server Version: v1.33.6

Example Ingress with invalid modsecurity-snippet:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-modsec
  annotations:
    modsecurity-snippet: |
      SecRule INVALID SYNTAX HERE "id:100,phase:2,deny"
spec:
  ingressClassName: nginx
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-service
            port:
              number: 80

How to reproduce this issue:

  1. Deploy ingress-nginx controller with ModSecurity enabled
  2. Create an Ingress resource with an invalid modsecurity-snippet annotation (as shown above)
  3. The Ingress is accepted without any validation or warning
  4. No error message is provided to the user about the invalid rule syntax

Expected result: Admission webhook should validate the modsecurity-snippet and either:

  • Emit a warning (in default mode), or
  • Reject the Ingress (in strict mode)

Anything else we need to know:

This is a security and operational concern because:

  • Invalid WAF rules may silently fail, leaving the application unprotected
  • Debugging issues becomes harder when rules fail at runtime instead of deployment time
  • Users don't receive any feedback about misconfigured security policies

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.needs-priorityneeds-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions