rfc-9485

I-Regexp: An Interoperable Regular Expression Format

C. Bormann, T. Bray
date2023-10 streamIETF areaart wgjsonpath statusPROPOSED STANDARD pages10 canonicalhttps://www.rfc-editor.org/rfc/rfc9485 doi10.17487/RFC9485 errataview
This document specifies I-Regexp, a flavor of regular expression that is limited in scope with the goal of interoperation across many different regular expression libraries.

Extracted elements (24)

design-rationale §6.1

Character class subtraction was omitted from I-Regexp because, although useful in XSD, it is absent from most parsing-regexp dialects and would prevent straightforward mapping.

json

design-rationale §6

I-Regexp intentionally supports only Boolean matching (not capture groups, lookahead, or backreferences) because parsing-regexp libraries accumulating these features have become susceptible to exploitable bugs and unpredictable performance leading to denial-of-service attacks.

json, security

design-rationale §1

I-Regexp was motivated by the JSONPath WG's need for a regexp mechanism interoperable across popular libraries. No suitable specification existed, so a new limited flavor was defined, inspired by the I-JSON approach of selecting a safe, interoperable subset.

json

design-rationale §6.1

Multi-character escapes (\d, \w, \s and their complements) were omitted because they exhibit large variation between regexp flavors, making interoperability impossible without them.

json

design-rationale §6.1

Unicode category escapes (\p{}/\P{}) were retained despite the challenge they pose for constrained environments because they are widely available in modern regexp libraries, and translating them to character-class matches would itself require access to the same Unicode tables.

json

interoperability-note §5.2

Any I-Regexp is also a valid XSD regexp; the mapping is the identity function. XSD 1.0 implementations incorporating errata are considered equivalent to XSD 1.1 for the purposes of this specification.

json

interoperability-note §5.4

For PCRE, RE2, and Ruby, perform the same dot substitution as for ECMAScript but enclose with \A(?: and )\z instead of ^(?: and )$.

json

interoperability-note §3

I-Regexp is defined as a subset of XSD regexp (XSD 1.0/1.1 Part 2), explicitly excluding character class subtraction, multi-character escapes (\s, \S, \w, etc.), and Unicode block references.

json

interoperability-note §5.1

Multi-character escapes unsupported in I-Regexp have direct substitutes: \S → [^ \t\n\r], \d → [0-9], and \p{IsBasicLatin} → [\u0000-\u007f]. Note that XSD's \d means \p{Nd} (all Unicode digits), not just [0-9].

json

interoperability-note §5.3

To use an I-Regexp as an ECMAScript regexp, replace any unescaped dot outside character classes with [^\n\r], then enclose the result in ^(?: and )$, and interpret as a Unicode pattern (the 'u' flag).

json

normative-requirement §3 REQUIRED

An I-Regexp implementation MUST be a complete implementation of the defined subset; in particular, full support for the Unicode functionality defined in the specification is REQUIRED.

json

normative-requirement §3 MUST NOT

An I-Regexp implementation MUST NOT limit itself to 7- or 8-bit character sets such as ASCII.

json

normative-requirement §3 MUST

An I-Regexp implementation MUST support the Unicode character property set in character classes (i.e., \p{} and \P{} category escapes).

json

normative-requirement §3 MUST

An I-Regexp MUST conform to the ABNF specification given in Figure 1 of the document, which defines the complete grammar for i-regexp, branch, piece, atom, quantifier, charClass, and related productions.

json

normative-requirement §3 MUST NOT

charClassExpr is not allowed to match the pattern [^]; although the grammar would parse it as a positive character class containing the single character '^', it is explicitly prohibited as an additional restriction.

json

normative-requirement §3.1 RECOMMENDED

Checking implementations — those that verify regexp compliance with the specification — are RECOMMENDED so that users have confidence they did not accidentally insert non-interoperable syntax. Low-effort implementations that simply map to another library via the Section 5 steps are excepted.

json

normative-requirement §3.1 SHOULD

Implementations SHOULD document whether or not they are checking implementations.

json

normative-requirement §4 MUST

Implementations that interpret I-Regexps MUST yield Boolean results as specified in XSD Part 2: Datatypes [XSD-2].

json

protocol-element §3

I-Regexp syntax is defined by an ABNF grammar covering alternation (branch separated by '|'), quantifiers ('*', '+', '?', range-quantifier '{m,n}'), atoms (NormalChar, charClass, grouped i-regexp), character classes (dot, SingleCharEsc, charClassEsc, charClassExpr), and Unicode category escapes (\p{} and \P{}).

json

security-consideration §8

More complex regexp libraries may contain exploitable bugs leading to crashes and remote code execution. Implementations using such libraries should check vendor documentation for configurable mitigations and resource-consumption limits.

security, json

security-consideration §8

Non-checking implementations that delegate to an underlying regexp engine expose that engine's security limitations. A checking implementation is still RECOMMENDED even when an engine with built-in security measures (e.g., RE2) is used.

security, json

security-consideration §8

Range quantifiers (e.g., a{2,4}) pose particular challenges; implementations may limit composability (disallowing nested range quantifiers) or range magnitude (disallowing very large bounds such as a{20,200000}), or detect and reject excessive resource consumption they cause.

security, json

security-consideration §8

Regexp engines often exhibit hard-to-predict performance, enabling denial-of-service attacks via attacker-controlled expressions. I-Regexp is designed to allow implementations that run in linear time and space in the input, and that detect when this cannot be guaranteed.

security, json

security-consideration §8

UTF-8 security considerations from RFC 3629 Section 10 apply to I-Regexp implementations; in particular, implementations may need to mitigate platform limitations regarding invalid UTF-8 sequences, as described in RFC 3629 Section 3.

security, json