How the CNN-GRU model decides
DAV NGWAF reads each request as a sequence of characters. A convolutional network finds suspicious fragments, a recurrent network judges what those fragments mean together, and the result is a single score. A policy layer turns that score into an action.
Two kinds of neural network work in stages:
- CNN (Convolutional Neural Network): finds short local patterns, such as
../,%27,UNIONor.env. - GRU (Gated Recurrent Unit): reads those patterns in order and judges context: whether they form an attack or just happen to appear in a normal URL.
The output is a probability that the request is malicious. The model never bans on its own: DAV NGWAF's policy layer combines the score with rules, exemptions and behavior over time before anything is enforced.
1. Turning a request into numbers
A neural network only works with numbers, so each request (mainly the path and query string) is converted first:
- Tokenize by character. Attacks hide in unusual characters and encodings (
%27,../,<,;), so character-level input holds up better against obfuscation than word-level input. - Map to integer IDs. Each character gets an ID from a fixed vocabulary.
- Pad or truncate to a fixed length, so every request has the same shape.
- Embedding layer. Each ID becomes a small learned vector. During training, characters that behave alike end up close together, for example
'and%27.
The result is a matrix of sequence length × embedding size, for example 200 × 32.
2. CNN: the local pattern detector
CNNs are best known for images. For text, a one-dimensional convolution slides along the character sequence.
- A filter is a small window of learned weights, for example five characters wide. At each position it scores how closely the characters under it match its pattern.
- The network has many filters, and each learns its own pattern during training. Nobody writes them by hand: training finds the fragments that separate attacks from normal traffic, such as
../,%2e%2e,<scr,' OR,/etc/andwp-admin. - Several filter widths can run in parallel to catch both short and longer fragments.
- ReLU activation keeps only positive matches. Max pooling keeps the strongest response in each region, which shortens the sequence and makes detection tolerant of position:
../counts the same at character 10 or 40.
In effect the CNN is a learned, fuzzy fragment matcher. It still responds to variations that an exact rule would miss: mixed case, partial encoding, inserted characters. Every window is computed independently, so it is fast.
What a CNN does not do well is understand order. It can tell that UNION and FROM are present, but not that they appear in sequence, inside a parameter value, right after a quote. That is the GRU's job.
3. GRU: the context and order reader
A GRU is a recurrent neural network. It reads a sequence one step at a time and carries a hidden state forward: a running memory of what it has seen so far.
Simple recurrent networks forget over long sequences. A GRU fixes this with two learned gates that output values between 0 and 1. At each step t, with input xt and previous state ht−1:
Update gate: z_t = σ(W_z·x_t + U_z·h_(t−1) + b_z)
Reset gate: r_t = σ(W_r·x_t + U_r·h_(t−1) + b_r)
Candidate: h̃_t = tanh(W_h·x_t + U_h·(r_t ⊙ h_(t−1)) + b_h)
New state: h_t = (1 − z_t) ⊙ h_(t−1) + z_t ⊙ h̃_t
σ = sigmoid, ⊙ = element-wise multiplication
- Reset gate: how much of the past to use when reading the current input. A value near 0 starts a fresh context, for example where a new query parameter begins.
- Update gate: how much to keep the old memory and how much to replace it. This lets the network hold on to “a quote broke out of a value earlier” until
SELECT … FROMappears.
Why a GRU and not an LSTM: an LSTM uses three gates and a separate cell state. A GRU uses two gates and one state, so it has roughly a quarter fewer parameters, runs faster, and performs comparably on short sequences such as URLs. That suits per-request inference on CPU.
4. How they work together
Request URL (string)
│
▼
Character IDs → Embedding 200 × 32
│
▼
Conv1D filters + ReLU 200 × 128 which fragments appear where
│
▼
Max pooling 50 × 128 shorter, position-tolerant
│
▼
GRU reads the 50 feature steps in order
│
▼
Final hidden state one vector summarizing the request
│
▼
Dense layer → Sigmoid P(malicious), from 0 to 1
Dimensions are illustrative and do not describe the production model's exact layers.
The two networks cover each other's weaknesses. The CNN compresses raw characters into a shorter sequence of pattern features, so the GRU reads a few dozen meaningful steps instead of hundreds of raw characters. The GRU adds the order and context the CNN lacks.
Worked example
Attack
/index.php?id=1%27%20UNION%20SELECT%20password%20FROM%20users--
CNN: filters respond to %27 (encoded quote), UNION, SELECT, FROM and -- (SQL comment).
GRU: reads them in order: a parameter value, then a quote that breaks out of it, then UNION SELECT, then FROM, then a comment that ends the query. That sequence is the injection signature, and the hidden state builds evidence step by step.
Score: high (e.g. 0.98)
Benign request with similar words
/blog/union-select-committee-report
CNN: some of the same filters may respond weakly to union and select.
GRU: the words are in the path, separated by hyphens, with no quote, no parameter break-out, no FROM and no comment. The context does not match an attack.
Score: low (e.g. 0.07)
A keyword rule would flag both requests. The model can flag suspicious URL patterns that match no blocklist entry, and avoid flagging benign URLs that happen to contain a keyword.
Scores are illustrative. Real values depend on training data.
5. From score to WAF decision
The model produces a probability. DAV NGWAF's policy layer decides what happens with it:
| Signal | Role in the decision |
|---|---|
| ML score | Compared against thresholds, for example malicious vs suspicious. Thresholds trade detection rate against false positives. |
| Deterministic rules | MITRE ATT&CK pattern matches, sensitive-file patterns, known bad user agents, and requests the web server already rejected. |
| Exemptions | Allowlisted paths, allowlisted IPs and protected addresses are checked first and are never banned, whatever the score. |
| Behavior over time | Repeated hits from one source, and correlation across addresses in the same subnet. |
| Mode | Monitor-only logs the decision. Enforcement blocks subsequent traffic from the source IP at the firewall, can clear tracked flows with conntrack, and can use XDP to drop packets before they reach the web server. |
Allowlists, paths and ban patterns live in operator-editable files that the engine picks up on reload, with no rebuild required.
6. Why it runs on CPU
Once trained, inference is a fixed series of operations: embedding lookup, convolution, GRU gate arithmetic, a dense layer and a sigmoid. A compact CNN-GRU model has a modest number of weights, so scoring one URL takes microseconds to low milliseconds on a modern CPU.
In DAV NGWAF the trained model is compiled into the Rust engine. No Python runtime, no separate inference service, and no model files are shipped. CPU is the default. GPU acceleration is an option for very large deployments. GPUs matter mainly for training, where the model processes large labeled datasets many times over.
Why not a transformer?
Transformer models such as BERT are the standard for natural-language tasks, but they are a poor fit for scoring every request on a web server:
| Compact CNN-GRU | Transformer (BERT-base) | |
|---|---|---|
| Size | A small fraction of BERT's weights | About 110 million parameters, 12 layers |
| Cost vs input length | Grows linearly | Self-attention grows with the square of the length |
| Per-request CPU time | Microseconds to low milliseconds | Typically tens of milliseconds or more without a GPU |
| Memory | Small, compiled into the engine | Hundreds of megabytes per loaded model |
| Hardware | CPU by default | Usually needs a GPU at high request rates |
URLs are short and structured. What matters is local fragments and their order, which is exactly what convolution and recurrence capture. A transformer's extra capacity helps with long, ambiguous human language, not with spotting ../ followed by /etc/passwd. A CNN-GRU gives the detection the job needs at a cost that lets every request be scored on ordinary CPUs.
Training in brief
- Data: labeled requests, malicious (attack payloads, scanner traffic, real detections) and benign (normal site traffic).
- Objective: binary cross-entropy. Backpropagation adjusts every weight: embeddings, filters, GRU gates and the output layer.
- Imbalance: real traffic is mostly benign, so training uses weighting or resampling. Otherwise a model that always answers “benign” looks accurate and is useless.
- Evaluation: precision, recall and false-positive rate on data the model has never seen, not just accuracy.
7. In practice
Most traffic a WAF actually sees is not a tailored attack. It is automated, low-cost reconnaissance that sweeps the internet looking for anyone who left a secret in a web root. A typical burst, all from one source within one second:
reason=blocklist_regex credential files .aws/credentials, .git-credentials, .npmrc, .pgpass, SSH keys
reason=blocklist_regex deployment config docker-compose.yml, CI files, appsettings.json
reason=bad_user_agent scanner nmap
That is the threat most small and mid-size sites face: high volume and low effort. Deterministic rules catch the known shapes, the CNN-GRU model catches variations that match no rule, and behavioral correlation catches persistent sources whatever their payloads look like.
- False positives: every WAF has them, at every price point. DAV NGWAF manages them with exemptions checked before any ban, monitor-only mode for new deployments, and editable allowlists.
- New attack types: they are detected and flagged so pattern and model updates can follow. Pattern files can be updated between releases without rebuilding the engine.
Summary
The CNN learns which fragments look dangerous. The GRU learns whether those fragments, in that order and context, form an attack. The sigmoid output is a confidence score, and DAV NGWAF's policy layer turns that score, together with rules, exemptions and behavior, into a decision: log, ban or ignore.