# Regex anchor bypass via line terminators

Anchored validators with m/s flags, or indices computed on transformed strings, letting injected markup or paths through

_Area: Web injection and code execution. Seen in 2 disclosed reports; latest 2026-09-08. Updated 2026-11-15._

## How it works

A validator or security check assumes `^...$` means "the whole string." Under the `m` (multiline) flag, `^` and `$` match at every line boundary, so `.test()` passes if *any one line* conforms — trailing content after a newline is never examined [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-vr34-hp96-76pp.md). The same class appears when two components disagree on what a line break is: a Go regex treats `\r` as ordinary content while the YAML parser treats it as a line terminator, so a check and the parser see different documents [E1](https://bugbountylibrary.com/r/blog%3Awiz-io-blog-nuclei-signature-verification-bypass.md). A third shape: an index or length computed on a transformed copy of a string but applied to the original, where the transform changes byte length [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-g966-83w7-6w38.md).

## Where it shows up

- Shared regex builders that add `m`/`s` flags to anchored productions used as full-string validators [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-vr34-hp96-76pp.md)
- Security-critical extraction done with regex, then the same bytes handed to a real parser (YAML, XML) [E1](https://bugbountylibrary.com/r/blog%3Awiz-io-blog-nuclei-signature-verification-bypass.md)
- "Find first" verification paired with "remove all" sanitization on the same input [E1](https://bugbountylibrary.com/r/blog%3Awiz-io-blog-nuclei-signature-verification-bypass.md)
- Validators for XML literals (publicId/systemId, PubidLiteral/SystemLiteral) that emit values verbatim into markup [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-vr34-hp96-76pp.md)
- Byte indices or lengths derived from `ToLower`, normalization, or case-folding and then used to slice the original string [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-g966-83w7-6w38.md)
- Path splitting that lowercases before computing a split position [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-g966-83w7-6w38.md)

## How to review

State the invariant explicitly: *the validator must accept a string only if the entire byte sequence conforms, and the parser must consume exactly the bytes the validator approved.* Check:

- Does the anchored regex carry `m` or `s`? If so, `^...$` is per-line, not full-string — require `\A...\z` or an explicit full-length check [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-vr34-hp96-76pp.md).
- Is the same input parsed twice by different engines? Enumerate every character each treats as a line break or comment start (`\r`, `\n`, `\r\n`, `#`) and confirm both agree [E1](https://bugbountylibrary.com/r/blog%3Awiz-io-blog-nuclei-signature-verification-bypass.md).
- Does verification cover every digest/record that sanitization removes? Count must match [E1](https://bugbountylibrary.com/r/blog%3Awiz-io-blog-nuclei-signature-verification-bypass.md).
- Is any index computed on a transformed string applied to the original? Require the transform to be length-preserving, or recompute on the original [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-g966-83w7-6w38.md).
- Are validated values later concatenated into markup without escaping? [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-vr34-hp96-76pp.md)

## How finders spotted it

- Noticed a shared `reg()` builder compiled anchored productions with the `m` flag, hypothesized a full-string `.test()` would accept one conforming line, then tried a valid literal plus newline plus breakout markup [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-vr34-hp96-76pp.md).
- Code review flagged three smells at once — regex in security-critical logic, find-first vs remove-all mismatch, and dual parsers on the same content — then tested Go regex behavior with `\r` to confirm the differential [E1](https://bugbountylibrary.com/r/blog%3Awiz-io-blog-nuclei-signature-verification-bypass.md).
- Code review of `splitPos`/`splitCgiPath` exposed the assumption `len(ToLower(path)) == len(path)`; knowing Go's `ToLower` can expand UTF-8 byte length, the researcher built a PoC showing the index mismatch [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-g966-83w7-6w38.md).

## Variants seen

- Multiline-flag anchor bypass in an XML literal validator, injecting DOCTYPE markup [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-vr34-hp96-76pp.md)
- Parser differential on `\r` between regex verification and YAML parsing, hiding unverified templates [E1](https://bugbountylibrary.com/r/blog%3Awiz-io-blog-nuclei-signature-verification-bypass.md)
- Length-changing case-folding shifting a split index, confusing SCRIPT_NAME/PATH_INFO [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-g966-83w7-6w38.md)

## Impact and severity

E2 chains onto an earlier DocumentType-injection mitigation: apps that adopted `requireWellFormed` to stop injection remain exposed, and injected entities reach downstream parsers [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-vr34-hp96-76pp.md). E1 defeats signature verification of scanner templates, allowing unverified code-protocol templates [E1](https://bugbountylibrary.com/r/blog%3Awiz-io-blog-nuclei-signature-verification-bypass.md). E3 escalates a benign-extension file upload to remote code execution via path confusion [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-g966-83w7-6w38.md). Severity rises with what the bypassed check protected and whether a second weakness (upload, downstream parser) is reachable.

## Seen in real software
Open-source packages and projects, and products, where this pattern was found. If the target runs one, compare the version it runs with the fix.
- **@xmldom/xmldom (npm)** >= 0.9.10, <= 0.9.11, fixed in 0.9.12: xmldom: requireWellFormed DocType publicId/systemId validation is bypassable via an embedded line terminator (CVE-2026-83618). Report: https://bugbountylibrary.com/r/ghsa%3AGHSA-vr34-hp96-76pp.md. Fix: https://github.com/xmldom/xmldom/commit/7b2ec67e1750daadd0bb06c92e875e726544a362
- **Nuclei** (signature verification) fixed in 3.3.2: Breaking the Chain: Wiz Uncovers a Signature Verification Bypass in Nuclei, the Popular Vulnerability Scanner (CVE-2024- (CVE-2024-43405). Report: https://bugbountylibrary.com/r/blog%3Awiz-io-blog-nuclei-signature-verification-bypass.md

## Evidence
- E1: https://bugbountylibrary.com/r/blog%3Awiz-io-blog-nuclei-signature-verification-bypass.md
- E2: https://bugbountylibrary.com/r/ghsa%3AGHSA-vr34-hp96-76pp.md
- E3: https://bugbountylibrary.com/r/ghsa%3AGHSA-g966-83w7-6w38.md
