Abstract
Why do injection, request smuggling, path traversal and XML signature wrapping keep recurring, and does one explanation cover them? Language-theoretic security (LangSec) proposes that code accepting input is a recogniser for a formal language, and that failures follow when a format demands more computational power than its recogniser can safely manage, or when two components interpret the same input differently. The theorems it relies on are correct and general: they rule out an algorithm that decides equivalence for arbitrary context-free descriptions. They do not explain why particular parsers disagreed. The case studies do that work. In the differentials examined here, in ZIP archives, JSON documents, property lists and ASN.1 certificate names, two parsers of the same bytes resolved duplicate names differently, accepted an OID encoding that X.690 forbids, cut a counted string at a NUL, or tolerated a malformed comment in different ways. The practical lessons hold: specify the grammar first, choose the weakest workable format, validate each unit before acting on it, use canonical encodings, and reject what the grammar does not allow. RFC 9413 reached a related position on Postel’s principle from interoperability experience.
Inputs as languages
The claim
The LangSec project states its position in one sentence: the only path to trustworthy software that takes untrusted input is “treating all valid or expected inputs as a formal language, and the respective input-handling routines as a recognizer for that language”. It adds two conditions. Recognition must be feasible, and “the recognizer must match the language in required computation power”. When input handling is written ad hoc, the de facto recogniser is scattered through the program, and for complex input languages full recognition “may be UNDECIDABLE”.1
The founding technical report, by Len Sassaman, Meredith Patterson, Sergey Bratus, Michael Locasto and Anna Shubina (Dartmouth TR2011-709, November 2011, later in the IEEE Systems Journal), splits the problem in two. From the single-component perspective, a component must accept inputs across an interface and be able to reject malicious ones “without losing integrity”. From the multi-component perspective, components that exchange messages must interpret them identically, yet different implementations of one protocol produce “mutually intelligible dialects” whose differences stay hidden until someone looks for them.2 The two halves need different evidence, and later sections treat them separately.
One model for several bug classes
The report models a message as M, an encoder E and a decoder D. Trouble starts when D(E(M)) ≠ M, so the destination acts on something other than what the source meant. An attacker who can alter E(M) in the channel is a man in the middle; one who can shape M before encoding is an injector. Both affect systems where the set of messages the source can generate is a subset of those on which the destination can operate.2
The familiar bug classes fit this model in some of their forms, and the conditions matter:
- Injection. The report places injection where one component takes user input to construct an input for another, such as a database or a shell, and says that all types of injection “leverage a weak boundary between control and data channels”. The engine parses a language much larger than the developer intended to use, and the input moves from a data position into a syntax position.2 The site’s article on injection flaws covers the mechanism and the defences.
- Request smuggling. RFC 9112 describes smuggling as exploiting “differences in protocol parsing among various recipients”. One documented mechanism is a message carrying both Transfer-Encoding and Content-Length: the specification says Transfer-Encoding overrides, and that such a message “ought to be handled as an error”, but a front end and a back end that resolve it differently disagree about where a request ends.3 See request smuggling.
- Path traversal. CWE-22 defines the weakness as building a pathname from external input without neutralising elements that let it “resolve to a location that is outside of the restricted directory”. That needs no second parser: one consistent reading and a missing confinement check suffice. The differential form arises when decoding is involved, and CWE’s mitigation addresses it: inputs “should be decoded and canonicalized to the application’s current internal representation before being validated”, and the application should not “decode the same input twice”.4 See path traversal.
- Signature wrapping. Verification and application logic select different elements from the same parsed tree. The W3C’s best-practice note for XML Signature tells applications checking a reference to check both the name and the position of the referenced element.5 See SAML signature wrapping, and for a JSON analogue with duplicate member names, JWT verification failures.
These examples fail at four different points: acceptance (which byte strings the parser admits), interpretation (what an admitted string means), selection (which part of the parsed result is used) and authorisation (whether the requested action is allowed). LangSec addresses the first two directly, and the third when selection is written into the grammar. The report also scopes something out. It does not consider cases where D(E(M)) = M but different destinations respond to the same M differently; those are “divergent program semantics”, outside its scope.2 That exclusion returns in the last section.
The formal language theory that matters
The hierarchy as machines
The Chomsky hierarchy classifies languages by the grammar that generates them and, equivalently, by the weakest automaton that recognises them; Chomsky’s 1959 paper showed that each restriction on grammars yields a proper subset of the languages of the previous one, and that the most restricted, type 3, are exactly the languages of finite automata.6 The LangSec papers use the automaton side because it maps onto code, and they insert one class that is not a Chomsky level: the deterministic context-free languages, a proper subclass of the context-free languages.27
| Class | Recogniser | Membership | Equivalence of two arbitrary descriptions |
|---|---|---|---|
| Regular | finite-state machine | decidable; one left-to-right pass, linear time, by a fixed deterministic finite automaton | decidable |
| Deterministic context-free (subclass of context-free) | deterministic pushdown automaton | decidable; linear time by a parser generated from a fixed LR(k) grammar | decidable8 |
| Context-free | non-deterministic pushdown automaton | decidable | undecidable |
| Context-sensitive | linear-bounded automaton | decidable, potentially very costly | undecidable |
| Recursively enumerable | Turing machine | semidecidable: a recogniser halts on members and may run forever on non-members | undecidable |
The membership column follows the report’s account: every class below the recursively enumerable is decided by an automaton that always halts in an accept or reject state, while a recogniser for an arbitrary recursively enumerable language may fail to halt on non-members, which the report calls a “syntactic denial of service”.2 Many individual recursively enumerable languages are decidable; the row describes what the class guarantees, not every member. The linear-time entries assume the automaton or grammar is fixed in advance. For the deterministic row, Knuth’s 1965 paper defined LR(k) grammars, in which the input is followed by k end-of-input markers, showed that a language has an LR(k) grammar if and only if it is deterministic, and described parsing with “an execution time at worst proportional to the length of the string being parsed”.9 The equivalence column concerns arbitrary descriptions in each class, as stated in the LangSec papers.27 It also concerns only the set of accepted strings. Two parsers that accept exactly the same strings can still return different trees or values. The incidents below show disagreement on particular inputs; none of them establishes, or depends on, a comparison of the two parsers’ entire accepted languages.
The right-hand column is what separates the two halves of the LangSec claim: the single-component question is membership, and the multi-component question is equivalence. The report also defines three properties of a parser. It is sound if it accepts only strings in the language, complete if it accepts every string in the language, and terminating if it halts on every input. Its design rule, “use a sufficiently strong parser for an input language, but no stronger”, echoes the W3C’s 2006 Rule of Least Power, whose good-practice statement is to “Use the least powerful language suitable for expressing information, constraints or programs on the World Wide Web.”210
What becomes undecidable
Three results carry the argument.
- Equivalence and containment of context-free grammars. Given two arbitrary context-free grammars G and H, both L(G) = L(H) and L(G) ⊆ L(H) are undecidable.2 If two parsers are modelled as two such grammars, no algorithm decides for every such pair whether they accept the same inputs.
- Ambiguity. Whether an arbitrary context-free grammar is ambiguous is undecidable, although approximate detectors exist.2 Subclass tests give a sufficient condition. Every LR(k) grammar is unambiguous, and Knuth gave a procedure that decides, for a given k, whether a grammar is LR(k); he also proved that whether a grammar is LR(k) for some k is undecidable.9 A format designer can therefore check a grammar against LR(1), say, but cannot ask an algorithm whether any amount of lookahead would suffice.
- Rice’s theorem. No total procedure decides, for every program, a non-trivial property of the language that program accepts. That rules out a general automatic checker for arbitrary recognisers; it does not prevent a particular hand-written parser from being verified. The Seven Turrets paper cites the theorem to argue for constructing parsers from formal grammars, as automata of the right class, rather than reasoning about arbitrary code.11 The site’s article on computability and complexity gives the theorem, its reduction from the halting problem, and the limits of what it says.
Equivalence for deterministic pushdown automata, the machines behind LR parsing, was posed by Seymour Ginsburg and Sheila Greibach in 1966 and settled by Géraud Sénizergues, who showed it decidable. His paper occupies pages 1 to 166 of Theoretical Computer Science volume 251 (2001) and won the 2002 Gödel Prize.812 That is why the LangSec papers draw their line at deterministic context-free: it is the most expressive class in their table for which equivalence of arbitrary descriptions is decidable.11 The length of a proof and the cost of the algorithm it yields are separate matters. Petr Jančar later gave a short self-contained decidability proof, and his abstract records that Colin Stirling derived a primitive recursive upper bound on the complexity of the problem.13 The Seven Turrets authors judge Sénizergues’ formal system “hardly practical for software developers to verify implementations”, valuable for showing that mechanical verification is possible.11 For regular languages the same question is routine, because two finite automata can be minimised and compared.
Two corrections to the folklore
The early papers contain a mistake that propagated. The technical report says “All unambiguous context-free grammars are deterministic”, and the companion ;login: article says unambiguous context-free grammars “need deterministic pushdown automata”.27 The containment runs the other way. Every deterministic context-free language has an LR(1) grammar, and LR(k) grammars are unambiguous.9 But some languages with unambiguous grammars are not deterministic. The standard example is the non-empty even-length palindromes over {a, b}, generated by S → aa | bb | aSa | bSb; each production fixes the outermost pair of symbols, so every string has exactly one derivation. Claus and Olderog’s lecture notes prove (Theorem 6.7) that this language is not deterministic context-free, by intersecting the strings that have no proper prefix in the language with a regular set and applying the pumping lemma to the result.14 The practical recommendation survives, since LR-parsable formats are still the safe target, but “unambiguous” is not a test for “deterministic”, and a format designer who checks only for ambiguity has not shown that a linear-time deterministic parser exists.
The second correction concerns machines. The undecidability results are about unbounded automata. A deployed parser runs with fixed memory and is, in principle, a finite-state system. The Seven Turrets paper uses a different comparison, saying that most systems “are not actually universal Turing machines” and are closer to linear-bounded automata.11 That model has memory that grows with the input. For a linear-bounded automaton, whether it halts on one given input can be decided by exploring its finite graph of configurations; that gives no procedure for termination across all inputs, or for equivalence. The theorems therefore rule out a general tool that certifies agreement between arbitrary parsers. They make no prediction about whether a particular test campaign will miss a particular difference, and differential testing does find disagreements.
Length fields and the Chomsky class
The technical report states that any grammar in which the value of one element influences the structure of another part of the string is at least context-sensitive, and gives HTTP’s Content-Length and IPv4’s header-length fields as examples. It also argues that PKCS#1 v1.5 signature padding is context-sensitive, building a linear-bounded automaton for it and applying the pumping lemma.2
Both statements need care. A 16-bit length field admits at most 65,536 values. If the whole message is also bounded, its language is finite, and every finite language is regular; a bounded field alone does not bound a message that repeats fields. The PKCS#1 lower-bound argument does not work as written. It reasons with the modulus size held fixed, for which the set of valid padded blocks is finite, while the claim concerns the language over all sizes. In RFC 8017 the intended length of the encoded message, emLen, is an input supplied from outside: the encoded message is 0x00 || 0x01 || PS || 0x00 || T, where PS is emLen − tLen − 3 octets of 0xFF and at least 8 octets long.15 If emLen is erased and any padding run of at least eight 0xFF octets is allowed, the valid strings (the fixed prefix, the padding run, a zero octet, one of a fixed set of digest-algorithm prefixes and a digest of the matching length) form a regular language. The security requirement is to check the padding against the externally known length. Bleichenbacher’s 2006 forgery, which the report cites, worked against implementations that did not validate the padding bytes correctly.2
What a class assignment captures is the shape of the recogniser. A regular expression for “a 16-bit length followed by that many bytes” exists but is unusable, whereas a parser that reads the length and then counts is short and obviously correct. Tools built after the 2011 papers treat data-dependent lengths as a first-class construct for this reason: Nail has “dependent fields” for size and offset fields, and EverParse’s specification language pairs a size field with an array whose size in bytes is “exactly size”.1617
The Chomsky label is therefore a proxy for a design property: how much state a recogniser must carry and how far a value in one place constrains bytes elsewhere. The 2017 ;login: article by Bratus and colleagues illustrates the cost with nested objects that each carry a length field. All those lengths must agree with one another and with the message length, which, the authors write, “may be a quadratic number of checks on these fields alone”.18 Heartbleed is their example. RFC 6520 requires the declared payload, three bytes of header and at least 16 bytes of padding to fit within the record, and says a HeartbeatMessage whose payload_length is too large “MUST be discarded silently”; OpenSSL used the declared length without that check.1918
From theory to protocols
Parse-tree validation, 2005
Before the name LangSec existed, Robert Hansen and Meredith Patterson presented Dejector at Black Hat in 2005. Given a set of known-good SQL queries and the database’s own grammar, it derived a sub-grammar that generates exactly the structures of those queries and used a parser generator to build a recogniser for that sub-language. Any query whose parse tree did not match one of the known shapes was rejected.2
The 2011 report used Dejector to criticise later research. Several validators modelled the acceptable queries as a regular language, following a string analysis in which the strings a program can generate are computed and then widened to a regular language for tractability.2 That approach involves two separate approximations. In “Static Checking of Dynamically Generated Queries in Database Applications” (ICSE 2004), Carl Gould, Zhendong Su and Premkumar Devanbu widen the grammar of strings generated by the application to a regular language, and note that in the string analysis they build on, by Christensen, Møller and Schwartzbach, the SQL grammar is instead narrowed to a finite-state automaton for syntax checking.20 The LangSec report quotes the 2007 journal paper of the same title, by Gary Wassermann with the same three authors, as saying that in practice they did not find “a function that concatenates some string, the return value of a recursive call to itself, and another string”. That observation concerns the first approximation, the application’s code. The report’s rejoinder concerns the second: in PostgreSQL’s bison grammar it found four productions of that recursive shape, including balanced parentheses and mutually recursive expression rules, which are where user input typically lands.2 The finding does not contradict what Wassermann and colleagues observed about application functions. It shows that the target SQL syntax is not regular, so a finite-state approximation of it cannot be exact. Other validators used an ANSI SQL grammar rather than the target database’s, which leaves room for inputs that “look right” to the validator but behave differently in the database.2 The report cites CVE-2006-2313 and CVE-2006-2314 as examples of a string read one way before it reaches the server and another way by the server. PostgreSQL’s advisory describes the first as invalidly encoded multibyte characters bypassing standard string-escaping methods, and the second as the practice of escaping a single quote as \' becoming unsafe in multibyte encodings, such as SJIS, BIG5 and GBK, that allow 0x5c (backslash) as the trailing byte of a character.21 Both criticisms anticipate the main themes: the recogniser must be strong enough, and it must read input the way the downstream component does.
PKI Layer Cake, 2009
In August 2009 Dan Kaminsky, Len Sassaman and Meredith Patterson released “PKI Layer Cake: New Collision Attacks Against the Global X.509 CA Infrastructure” through IOActive; the version in the Financial Cryptography 2010 proceedings drops “CA” from the title.2223 Apart from an MD2 attack, the paper concerns how certificate authorities and browsers read the subject name. A CA checks a PKCS#10 certificate signing request and issues a separate certificate. If parts of the requested name that the CA did not validate are carried into the certificate, a browser may derive a different identity from the signed certificate than the one the CA checked. The authors found CA validation limited in practice to the Common Name, with other fields ignored.23 The Seven Turrets paper later credited the work with demonstrating “over 20” such differentials between the X.509 libraries of the time.11 The byte-level details are worked through in the next section.
2011 and 2012: the formal statement and the patch
Four publications in late 2011 and early 2012 set out the programme. The technical report gave the formalism, defined the “parse tree differential attack” (give two implementations identical input, compare the parse trees, and treat each deviation as a candidate vulnerability), and stated two principles: “Starve the Turing beast” by granting the minimum computational power, and “Secure composition requires parser computational equivalence”.2 The ;login: article “The Halting Problems of Network Stack Insecurity” restated these for practitioners.7
The companion ;login: article, “Exploit Programming: From Buffer Overflows to ‘Weird Machines’ and Theory of Computation”, supplied the attacker’s half. An exploit is a program; its instructions are the target’s features, errors and bugs; the collection of those artefacts is a “weird machine” inside the target. The attack, in the authors’ words, is “a constructive proof that such unforeseen computations are indeed possible”, and therefore evidence that the target contains the execution model the attacker described.24 The link to parsing is that the exploit program arrives as input and is processed first by the input-handling code, which either contains the artefacts or lets crafted input reach them.7
In the March/April 2012 issue of IEEE Security & Privacy, Sassaman, Patterson and Bratus published “A Patch for Postel’s Robustness Principle”. The proposed patch reads: “Be definite about what you accept”, treat valid inputs as formal languages and generate their recognisers from grammars, and treat input-handling computational power as a privilege to be reduced wherever possible.25
The Seven Turrets of Babel, 2016
Falcon Momot, Sergey Bratus, Sven Hallberg and Meredith Patterson turned the programme into a taxonomy for auditors at IEEE SecDev 2016. They name seven weaknesses: shotgun parsing (validation interleaved with processing); non-minimalist input-handling code; an input language more complex than deterministic context-free; differing interpretations of the input language; incomplete protocol specification; overloaded fields; and permissive processing of invalid input.11
Shotgun parsing is “throwing a cloud of checks at the input” and hoping that one catches each bad case; because validation and processing are interleaved, a late-discovered error means part of an invalid input has already been acted on, “with the consequence that program state is difficult to accurately predict”.11 The paper also tried to measure the effect. The authors reviewed the 47 OpenSSL vulnerabilities with CVE numbers from January 2015 to June 2016 and estimated that 35 (74.5 per cent) would have been averted by avoiding the listed antipatterns, 13 of them attributable mainly to shotgun parsing and 11 to processing input that should have been rejected. They classified none of the 47 as caused by an input language beyond deterministic context-free.11 That last detail is easy to miss, and it bears on how much weight the Chomsky argument can carry.
Curing the vulnerable parser, 2017
The 2017 ;login: article by Bratus, Hermerschmidt, Hallberg, Locasto, Momot, Patterson and Shubina recast the advice as three design patterns. The Recognizer pattern places a parser built from the input grammar in front of the business logic, which receives only parsed, typed data or an error. The Most Restrictive Input Definition pattern chooses the narrowest language that does the job. The Unparser pattern applies the same discipline to output: only a serialiser that knows the output language writes to the output channel, which is the general form of the prepared statement.18 The article also states a principle that later reappears in the type-driven literature: “what a deserializer cannot check, the rest of the code should not assume”.18
Parser differentials, byte by byte
One OID, three readings
An X.509 name is a sequence of relative distinguished names, each a set of attribute-type-and-value pairs; the attribute type is an ASN.1 object identifier (OID).26 The Common Name is OID 2.5.4.3, encoded in BER as:
06 03 55 04 03
06 tag: OBJECT IDENTIFIER
03 length: 3 content octets
55 0x55 = 85 = 40*2 + 5, the first two arcs "2.5"
04 arc 4
03 arc 3Each later arc is written in base 128, with the top bit set on every octet of the arc but the last. Kaminsky, Sassaman and Patterson asked what happens if a request carries a padded arc:
06 04 55 04 80 03
04 length: 4 content octets
80 continuation bit set, value 0
03 final octet, value 3: arc = 0*128 + 3 = 3Two checks are involved. The length octet must match the number of content octets, which it does here, and the content octets must form a valid OID. Arithmetically this is still 2.5.4.3, but X.690 forbids the encoding: a subidentifier “shall be encoded in the fewest possible octets, that is, the leading octet of the subidentifier shall not have the value 80” (hexadecimal), and the rule is part of BER itself, not only of the stricter DER.27 In the authors’ 2009 tests, OpenSSL’s OID resolver did not treat the padded value as the Common Name OID and displayed it as an unrecognised attribute, but did not reject the name either. Microsoft’s CryptoAPI stripped the padding and resolved it to Common Name. The authors framed the consequence conditionally: assuming the CA carried the padded attribute into the certificate as one more unrecognised element of the subject name, Internet Explorer would treat it as a Common Name.2223
The second variant uses overflow. The proceedings version describes it in simplified form as an arc of 2^64 + 3, and states that CryptoAPI at the time expected such integers to fit a 64-bit unsigned long and so read the arc as 3.23 The IOActive report’s test encoding was:
06 0D 55 04 82 80 80 80 80 80 80 80 80 80 03Here the arc is eleven octets: 0x82 contributes 2, nine 0x80 octets contribute zeros, and 0x03 contributes 3, so the value is 2·128^10 + 3 = 2^71 + 3. OpenSSL, which uses arbitrary-precision integers, printed it as 2.5.4.2361183241434822606851, which is exactly 2^71 + 3, and the report says Internet Explorer again became fully vulnerable.22 Both 2^64 + 3 and 2^71 + 3 reduce to 3 modulo 2^64.
In both variants, the signed bytes meant an unrecognised attribute to OpenSSL and a Common Name to CryptoAPI. No construct here needs more than a finite-state recogniser at the level of the OID’s content octets. The two variants failed differently. The padded form is an encoding X.690 forbids.27 The overflow form has no leading 0x80 octet, so the minimal-encoding rule is not at issue; it encodes a large arc, and the differential came, by the authors’ account, from one implementation’s fixed-width arithmetic.23
The NUL in the name
The same paper’s best-known attack used a NUL byte. ASN.1 strings carry an explicit length, so the length field does not stop a value containing 0x00. Whether a zero byte belongs in a given value is settled by other rules: the string type of the attribute (RFC 5280 requires conforming CAs to encode DirectoryString values as PrintableString or UTF8String, with listed exceptions) and, for a host name carried as a dNSName, the DNS “preferred name syntax”.26 Current guidance also takes the Common Name out of the question: RFC 9525 says it “MUST NOT be used to identify a service because it is not strongly typed”.28 The 2009 attack predates that guidance. Consider a requested name of www.bank.com\x00.badguy.com. In the report’s scenario, a CA checking domain control would see a host inside badguy.com and ask that domain’s owner. If it issued the certificate, CryptoAPI and Mozilla’s NSS, as they behaved in 2009, terminated the value at the NUL, as C strings do, and validated the certificate for www.bank.com; NSS also accepted *\x00.badguy.com as matching every name.22 In the report’s terms, the CA decoded the field as a Pascal-style string and the browser as a C-style one.2 Mozilla’s advisory credits Kaminsky with the report, notes that Moxie Marlinspike reported it independently, and lists the fix in NSS 3.12.3 and Firefox 3.0.13.29 The CVE record for CVE-2009-2408 says that NSS before 3.12.3, Firefox before 3.0.13 and two other Mozilla products “do not properly handle a ‘\0’ character in a domain name in the subject’s Common Name (CN) field of an X.509 certificate”.30
Android “Master Key”: two ZIP readers
An Android APK is a ZIP archive. Before installation, Android verified each entry’s signature using a Java ZIP implementation; the code that later loaded the application’s bytecode used a separate C implementation. Jay Freeman (saurik) described how each handled two central-directory entries with the same name, for example two entries called classes.dex.31
- The Java reader walked the central directory and inserted each entry into a
LinkedHashMapkeyed by file name. A second insertion with the same key replaced the first, so only the lastclasses.dexwas verified. - The C reader inserted every entry into an open-addressed hash table with linear probing and no replacement. Lookup scanned forward from the hash slot and returned the first match, so the first
classes.dexwas loaded.
An attacker could take a signed APK, insert a malicious classes.dex before the original, and obtain a package that verified with the original signature and ran the attacker’s code.31 The CVE record for CVE-2013-4787 gives the affected range as “Android 1.6 Donut through 4.2 Jelly Bean”, “aka Android security bug 8219321”.32 The fix that Freeman reproduced made the Java reader throw ZipException("Duplicate entry name").31 The Nail authors note that a second, different inconsistency between the same two ZIP readers was disclosed soon after.16 The Seven Turrets paper reports that the eventual remedy included handling the package “with the same parser”.11
CouchDB: two JSON readers
Apache CouchDB stores documents as JSON, is written in Erlang, and runs JavaScript validate_doc_update functions to vet writes. A user who creates an account must not be able to grant themselves roles. In 2017 Max Justicz found that the two JSON parsers disagreed about duplicate keys. Given {"foo":"bar","foo":"baz"}, the Erlang parser jiffy kept both pairs and CouchDB’s getter returned the first, while JavaScript’s JSON.parse kept the last.33 The request body that exploited this was:
{ "type": "user", "name": "oops", "roles": ["_admin"], "roles": [], "password": "password" }The JavaScript validator saw "roles": [] and allowed the write. The Erlang side, which made later authorisation decisions, saw "roles": ["_admin"]. Justicz noted that the admin web console showed the user’s roles as empty, because it too parsed the document in JavaScript.33 CouchDB’s advisory for CVE-2017-12635 (14 November 2017) rates it critical and describes the fix: Erlang parsing was changed “mimicking the JavaScript behaviour of picking the last key, if duplicates exist”.34
The JSON specification in force at the time, RFC 7159, said object names “SHOULD be unique”, that when they are not “the behavior of software that receives such an object is unpredictable”, and that “Many implementations report the last name/value pair only” while others report an error or every pair.35 RFC 8259, published the following month, kept that text.36 Base JSON therefore left duplicate handling open, and CouchDB’s two parser paths filled the gap differently. The fix aligned those two paths on last-wins, which the specification permits. The document also fails I-JSON conformance, since RFC 7493 says objects “MUST NOT have members with duplicate names”. I-JSON leaves the receiver’s response to the application protocol, which can require receivers to reject such messages or, in security protocols, not to trust them.37
Psychic Paper: four plist readers
On iOS, an app’s entitlements (privileges such as task_for_pid-allow) are an XML property list embedded in its code signature. For developer-signed apps, the userland daemon amfid checks that the entitlements are permitted by the Apple-signed provisioning profile; the kernel and system daemons later read the same entitlements to make access decisions. Siguza’s write-up of 1 May 2020 counts at least four plist parsers in iOS: OSUnserializeXML in the kernel, IOCFUnserialize in IOKitUser, CFPropertyListCreateWithData in CoreFoundation, and xpc_create_from_plist in libxpc. amfid used CoreFoundation. In his tests the two IOKit-family parsers always returned the same data.38
The proof of concept placed this inside the entitlements dictionary:
<!---><!-->
<key>platform-application</key><true/>
<key>com.apple.private.security.no-container</key><true/>
<key>task_for_pid-allow</key><true/>
<!-- -->Siguza reads <!---> and <!--> as invalid XML tokens; the IOKit, CoreFoundation and XPC parsers all accepted the sequence, but not in the same way. In the CoreFoundation code he quotes, the parser, positioned on the !, checks that the next two characters are dashes and advances its pointer by two, which leaves it on the second dash; its scan for --> then succeeds on the remainder of <!--->, so it reads a complete empty comment. The IOKit code consumes the ! and both dashes before scanning, so the -> that follows does not end the comment. The two parsers are then out of phase. CoreFoundation reads <!--> as the start of a comment and skips the three entitlements until the final -->; IOKit reads the --> inside <!--> as the end of its comment and parses the entitlements. Siguza observed that XPC, which he did not reverse-engineer, also saw the entitlements. amfid saw nothing to object to, while the kernel and daemons saw the privileges.38 According to Siguza, he found the bug in 2017 and it was fixed in iOS 13.5 beta 3, which Apple released the day before his post. He describes Apple’s fix as a new function, AMFIUnserializeXML, pasted into both the kernel extension and amfid, whose result is compared with those of the existing parsers; a mismatch is logged as “AMFI: detected an anomaly during entitlement parsing”. He notes that the malformed comment sequence still passes when nothing is placed between the comments.38
Go: case-folded keys and lenient XML
Trail of Bits described in June 2025 how Go’s standard parsers produce differentials. In their struct-decoding example, Go’s original encoding/json took the last of two duplicate keys and matched field names case-insensitively, so {"action":"Action1","aCtIoN":"Action2"} set the string field to Action2; the authors note that “almost no other parser has this behavior”. The folding also accepted two non-ASCII characters: the long s (ſ, U+017F) for s and the Kelvin sign (U+212A) for k. In their tests Go’s XML decoder accepted leading and trailing garbage around a document. That leniency figured in CVE-2020-16250, a HashiCorp Vault authentication bypass found by Google Project Zero: an attacker could make AWS STS return JSON instead of XML, and Vault’s XML parser extracted an identity from the JSON response.39 The only strictness switch in the original JSON package was DisallowUnknownFields.39 Last-wins describes the scalar field in that example. The package’s own security notes say later duplicate values “will replace or be merged into prior values, depending on the field type”: maps and structs are merged, other types replaced.40
The redesigned encoding/json/v2 first shipped in Go 1.25 as an experiment enabled by GOEXPERIMENT=jsonv2.41 Go 1.27, released on 19 August 2026, made it a standard package.42 Its release notes say v2 “rejects invalid UTF-8 in JSON strings and rejects duplicate names within a JSON object”, and the v2 documentation says unmarshalling matches struct field names case-sensitively by default.4344 In Go 1.27’s default build, the v1 package is backed by the v2 implementation with its marshalling and unmarshalling behaviour preserved; setting GOEXPERIMENT=nojsonv2 at build time restores the original v1 implementation, an opt-out the notes expect to remove in a future release.43 The v1 documentation says the package “unfortunately operates with less secure defaults”.45
What the fixes chose
Three of these cases were closed in three different ways.
- Reject. The Android patch that Freeman reproduced made the verifier refuse duplicate ZIP entries. The input that created the differential is no longer in the language accepted at that boundary.
- Align. CouchDB made the Erlang parser pick the last duplicate key, as JavaScript does. Duplicates are still accepted; the two parser paths named in the advisory now resolve them the same way.
- Compare. Apple added another parser and compares outputs. The check blocks the demonstrated mismatch, though by Siguza’s account the malformed comment sequence itself is still accepted when nothing is hidden between the comments.
The LangSec literature recommends the first. Each approach enforces a policy only where it is applied. A rejection rule protects nothing if some entry point bypasses it, an alignment holds only for the parsers that were aligned, and a comparison catches only the differences between the parsers it compares. The sources record what was done; they do not state the maintainers’ reasons for choosing one approach over another.313438
Postel’s principle, revised
What was said
RFC 9413 traces the robustness principle’s earliest form in the RFC series to RFC 760, the January 1980 Internet Protocol specification, where it follows a sentence that explains it: “While the goal of this specification is to be explicit about the protocol there is the possibility of differing interpretations.” The implementation “should be conservative in its sending behavior, and liberal in its receiving behavior.”4647 RFC 761, the TCP specification of the same month, gives the better-known wording: “be conservative in what you do, be liberal in what you accept from others.”48 RFC 1122 (1989) restated it as “Be liberal in what you accept, and conservative in what you send”, and in the same paragraph told implementers to “assume that the network is filled with malevolent entities that will send in packets designed to have the worst possible effect”.49 In its original setting, then, liberality came paired with an explicit warning about hostile senders.
The LangSec authors argued that the principle, read loosely, “maximizes interoperability at the unfortunate expense of consistent parser behavior”.2 Every receiver that accepts a malformed message and repairs it in its own way creates a dialect. The Seven Turrets paper lists “permissive processing of invalid input” as an antipattern and gives Heartbleed as an instance: a heartbeat request whose payload is shorter than its declared length is not a string in the TLS grammar, and OpenSSL processed it anyway.11 It also recommends against transparently correcting invalid input, because “using input correction code to apply a transformation to input to ‘activate’ a malicious payload is a favorite trick of attackers”.11
RFC 9413
The IETF reached a related position for different reasons. Martin Thomson’s individual draft on the subject, filed under the name draft-thomson-postel-was-wrong and titled “The Harmful Consequences of the Robustness Principle”, was replaced by an IAB draft that became RFC 9413, “Maintaining Robust Protocols”, by Thomson and David Schinazi (June 2023). It is an Informational document representing IAB consensus, not a standard.5046
RFC 9413 separates three aspects of robustness: to software defects, to attacks, and to “the unexpected”. The first two remain necessary. The third, tolerating inputs the specification did not anticipate, “is no longer considered best practice in all scenarios”. The RFC accepts the premise that specifications will be imperfect and adds: “ignoring faulty or ambiguous input is almost always the incorrect solution to the problem.”46
The IAB guidance argues from ecosystems. Tolerance causes “protocol decay”: errors become entrenched until every new implementation must be “bug-for-bug compatible”. Its example is TLS: some servers terminated connections when a ClientHello ended with an empty extension, so clients had to ensure the last extension was non-empty. The RFC describes two stable equilibria, one where most implementations are strict and newcomers must comply, and one where non-compliance is tolerated and newcomers must tolerate it too. Its remedy is “active protocol maintenance”. Under the heading “virtuous intolerance” it presents strictness as a choice with conditions: “Choosing to generate fatal errors for unspecified conditions instead of attempting error recovery can ensure that faults receive attention”; any intolerance “needs to be strongly supported by specifications”, or it fractures the protocol community; and stateless endpoints that would otherwise answer every unauthenticated sender “might need to silently discard these messages”. Where errors are reported, it prefers explicit messages, citing QUIC’s error frames.46
Four limits should be kept in view. RFC 9413 applies only where implementations can be updated; it says so in its applicability section. It records that it had “broad but not unanimous approval within the IAB”, reflecting concerns in the IETF community “about how broadly it applies in all situations”.46 Its security considerations section is brief and argues that hiding protocol variations conceals bugs; it does not cite or adopt the LangSec formal argument. And it does not ask for maximal strictness. It endorses protocols that “explicitly allow for a range of valid expressions of the same semantics, with precise definitions for error handling”, and gives BGP as an example: RFC 4271’s mandatory session reset for a malformed UPDATE was not widely implemented, many peers treated the affected route as withdrawn instead, and RFC 7606 documented that practice with precise rules.46
Definite tolerance
The HTML parsing specification illustrates that third option. It “defines the parsing rules for HTML documents, whether they are syntactically correct or not”, and the handling of each parse error is defined by the algorithm, although a user agent may abort at the first parse error it encounters.51 The algorithm also models interaction with scripts explicitly: input can be inserted into the stream being parsed through document.write, for which the specification tracks a script nesting level and a parser pause flag.51 Given the same input and the same parsing context, including scripting settings and any inserted input, conforming parsers that do not abort should build the same tree. HTML shows that the Postel patch’s “be definite about what you accept” can be met for malformed input when error recovery is specified completely.25
Parse, don’t validate
Alexis King’s 2019 essay “Parse, don’t validate” reached the LangSec conclusion from type-driven programming in Haskell. Her example compares two functions that check a list is non-empty. validateNonEmpty returns (), “the type that contains no information”; parseNonEmpty returns a NonEmpty a, a refinement of the input type that records what was learned. Both check the same thing. The difference, she argues, “lies almost entirely in how information is preserved”. After the parsing function runs, code that needs a non-empty list cannot be called with anything else, and the impossible case does not need handling again downstream.52
The essay cites the LangSec definition of shotgun parsing directly and adds a point about validation: with validation-based approaches it is “extremely difficult or impossible” to tell whether everything was really checked up front, or whether some supposedly impossible case can occur.52 Parsing into a precise type turns the Recognizer pattern into something a compiler enforces. The essay also corrects an over-literal reading of LangSec: “Plenty of useful parsers are context-sensitive”, and parsing in several passes is fine provided nothing acts on the input before it is fully parsed.52
King qualified the idea a year later. Wrapping a string in a named type with a checking constructor (“smart constructor”) gives a weaker kind of safety, because the guarantee depends on trusting the module that defines the type, whereas a type whose structure cannot represent invalid values depends only on the type checker.53 For input handling the distinction matters. An EmailAddress wrapper can centralise access to the string behind one module’s functions, so consumers use the same decoding; a parsed structure with the local part and domain as separate fields avoids decoding the string again at all. A wrapper that exposes the raw string invites each consumer to split it its own way, which reintroduces the chance of two readings.
What practitioners do
Write the grammar before the code
The Seven Turrets remedies begin with specification. A complete specification “leaves no bytes to chance”: character sets defined per field, and each field defined by meaning, allowed content, length and position. Where the specification is unclear, the decision should be documented, preferably in the grammar itself. If a buggy client must be supported, the authors recommend amending the specification to accept its output formally rather than treating it as an exception in code.11 RFC 9413 asks the same of protocol communities: when an implementer finds a condition the specification calls faulty without saying how to handle it, the fix belongs in the specification.46
For formats that already exist, the work starts by finding out what is actually accepted. DARPA’s SafeDocs programme was set up to extract “the extant formats’ de facto syntax”, including non-compliant syntax that is deliberately accepted and widely used, and then to identify simpler, unambiguous subsets (“safe sub-setting”) for which verified parsers can be built.54
Choose the least powerful format
The papers recommend staying at or below deterministic context-free, using regular languages where nesting is not needed, and avoiding constructs in which a value in one place changes the meaning of bytes far away.11 Two further rules from the Seven Turrets paper follow. Do not overload a field with special values; signal the presence or absence of an element with a separate field, or by the presence or absence of its representation. Do not embed a general-purpose language in a data format unless the use case requires it; the paper’s examples include Elasticsearch’s Groovy scripting and TrueType’s glyph programs.11
One recogniser per unit, before acting on it
Shotgun parsing is avoided by the Recognizer pattern: a parser derived from the grammar consumes a unit of input and returns either a typed structure or an error, and nothing else touches the raw bytes.18 The unit need not be the whole input. Microsoft’s Hyper-V deployment validated in layers, incrementally, to avoid the cost of validating an entire packet before processing; the discipline is that each unit, and whatever it depends on, is validated before anything acts on it.17 In a single program this is a matter of code structure. Across components, it means that the component that checks an input and the component that acts on it should use the same parse. Two ways achieve that:
- Share the parser. Use one library in both places, which is where, by the Seven Turrets account, the Android remedy ended.11 A shared library aligns behaviour only if both components call it at the same entry point, with the same configuration and on the same input boundaries.
- Pass the parse, not the bytes. Have the checker forward its parsed result, or a fresh serialisation of it produced by an Unparser, so the downstream component never sees the original ambiguous bytes.18 A signature verifier that returns the verified object, instead of a boolean beside the original document, follows this rule. The XML signature-wrapping attacks described in the SAML article exploit verifiers that do not.
Canonical encodings and duplicates
The byte-level cases above involve a value with more than one encoding, a repeated name whose meaning the format left open or the readers resolved differently, a counted string cut at a terminator, and malformed syntax tolerated in different ways. The defences are specific.
- Reject non-minimal encodings. X.690 already forbids padded OID arcs, and DER removes most remaining encoding freedom.27
- Reject duplicate keys and duplicate archive members. I-JSON forbids duplicate names; Go’s JSON v2 rejects them by default.3744
- Reject unknown fields where the schema is closed, and trailing data after a complete message.39
- Prefer formats whose parsers are non-malleable. The 2019 EverParse paper calls a parser secure when it is non-malleable, accepting at most one binary representation of each message, and complete, accepting at least one; a secure parser is then correct with respect to its unique serialiser. Its section 5 states non-malleability for parsers that may stop before the end of their input: if two successful parses return the same value, they consumed the same number of bytes and those bytes are identical.55 By that definition, a non-malleable OID parser could not accept both
55 04 03and55 04 80 03as 2.5.4.3. The property says nothing about bytes after the consumed prefix, which the caller must still check, and the parser follows X.690 only if the format description it was generated from does.
Length prefixes or delimiters
The choice of framing decides which failures are possible.
With delimiters, a field ends at a reserved byte: a quote, a newline, CRLF, a NUL. Data that could contain the delimiter has to be escaped, or the representation restricted so that it cannot occur, and every reader has to apply the same rule. Many injections are delimiter confusion, although input can also cross a syntax boundary without any quoting delimiter, as when unquoted numeric input is concatenated into a query. NUL-terminated string handling of length-delimited fields produced the X.509 attack.22
With length prefixes, the field’s size comes first, and arbitrary bytes, including NUL, are legal in the body. Daniel Bernstein’s 1997 netstrings are the minimal form, [len]":"[string]",", so “hello world!” becomes 12:hello world!,; leading zeros in the length are prohibited, which gives each string a single encoding, and the declared size lets an application “check in advance whether it has enough space”.56 The declared length is an untrusted claim. It has to be checked against bounds, the enclosing container and local policy before it drives allocation or copying; Heartbleed is the case where it was not.1918 Layer Cake shows the consequence when layers differ: a length-prefixed field can carry a NUL that a downstream C-string consumer treats as a terminator.22
Neither choice is safe by itself. The rules that survive both are: one framing mechanism per layer, never two that can disagree (HTTP/1.1’s Content-Length and Transfer-Encoding are the standard counter-example, and RFC 9112 now says a message carrying both “ought to be handled as an error”3; see request smuggling); every length checked against its container before use; and lengths and delimiters given a single canonical spelling.
Tools
Four tools from the research literature show the range of what is available.
| Tool | What it is | What it gives | Limits |
|---|---|---|---|
| Hammer | C parser-combinator library from the LangSec group, with bindings for several languages | grammar written as code; bit-oriented; packrat, LL(k), GLR, LALR and regular-expression back-ends57 | as of the 2014 Nail paper, no support for offset fields, checksums or compressed data beyond arrays immediately preceded by their length, and semantic actions written by hand16 |
| Kaitai Struct | declarative format language (.ksy) compiled to parsers in many languages | one description shared across languages; large format gallery58 | value validation (valid) only since v0.9; instances parse from arbitrary offsets and are lazy by default, so fields nobody reads are never checked unless the code forces them59 |
| Nail | grammar defines both the wire format and the in-memory object model (OSDI 2014) | no semantic actions; a “semantic bijection” lets one grammar parse and generate; dependent fields for sizes, offsets and checksums | its authors note that removing semantic actions “reduces the expressive power”16 |
| EverParse | generator of formally verified C parsers from message-format descriptions | proofs, against the specification generated from the format description, of memory safety, functional correctness and non-malleability; zero-copy | requires a precise specification of each format, which the proofs do not check against the protocol standard5517 |
Two stages of EverParse should be kept apart. The 2019 USENIX Security paper generated parsers and serialisers from tag-length-value format descriptions. Its front end, QuackyDucky, is kept outside the trusted computing base: it emits a formal specification with the code, and F verifies the generated code’s memory safety, functional correctness and non-malleability against that specification at source level. Carrying those guarantees to machine code relies on F and the Z3 prover, the KReMLin compiler to C and the C compiler. The authors trust the format description for liveness but not for security, and rely on interoperability testing to catch a description that does not match the real format. Where an untagged union takes its tag from the application, the paper gives only a conditional guarantee.55 The paper covered all TLS message formats from 1.0 to 1.3 (293 datatypes), Bitcoin blocks and transactions, and the DER payload of PKCS#1 signatures.55 Microsoft’s 2021 report describes later validators deployed in the Hyper-V Virtual Switch, which runs in the privileged root partition and handles guest network traffic. There the team specified more than a hundred message kinds across four protocol layers, EverParse produced about 30,000 lines of verified C, the code was proved free of double fetches, and the authors report no noticeable performance overhead. They also report that writing the specifications took “careful specification engineering and discovery”, because some formats were proprietary and long-evolved.17
Nail’s authors evaluated their tool by building a DNS server in under 300 lines of code and grammar and an unzip program, and motivated it with a survey. Searching CVE entries from 2010 to May 2014 that mention ZIP, they found 16 involving ZIP processing: 11 memory-corruption bugs, four parsing inconsistencies (their example is CVE-2013-1462, in which multiple virus scanners interpreted ZIP files incorrectly) and one semantic misunderstanding.16
Test for differentials
Since no general procedure certifies that two parsers agree, the practical substitute is to run them side by side. The technical report’s parse-tree differential method is exactly this: feed identical inputs to two implementations, compare the trees, and investigate every difference.2 Siguza’s write-up demonstrates the Psychic Paper bug with a small tool that parses one file with three of the plist engines and prints the results side by side.38 Any pipeline with a checking stage and an acting stage can be tested the same way, by sending the checker’s view and the actor’s view of generated inputs to a comparison, with emphasis on duplicates, non-minimal encodings, embedded terminators, odd case and Unicode folding, and leading or trailing data.
Where LangSec oversells
Undecidability explains little of these cases
The mechanisms in the differentials examined here did not depend on context-sensitive or richer constructs. The OID content octets form a regular language, JSON objects are deterministic context-free, and the ZIP and plist failures turned on duplicate names and on how a comment was scanned. The Seven Turrets authors, by their own classification, assigned none of the 47 OpenSSL vulnerabilities they reviewed to language complexity.11 The proximate causes were duplicate names resolved differently, acceptance of a forbidden OID encoding, C-string handling of counted strings, a pointer advanced by two characters where three were consumed, and, by the Layer Cake authors’ account, fixed-width arithmetic. The equivalence theorems explain why no tool will certify agreement between arbitrary parsers. They do not explain why these parsers disagreed, which was underspecification and ordinary bugs. A reader who concludes that staying below the decidability line is sufficient has drawn the weaker lesson from these cases.
Real parsers are finite, and the classification is a proxy
As shown above, a bounded message has a finite and therefore regular language, and the technical report’s PKCS#1 argument does not establish its lower bound. Undecidability results apply to idealised unbounded machines.2 The productive form of the argument concerns how much state and cross-field coupling a recogniser must manage, which is what makes nested lengths dangerous.18 Stated in that form, the claim is plainly true and does not need the hierarchy.
Some formats need computational power
Fonts with hinting programs, PDF with JavaScript, web pages, database query languages, configuration languages with templating and smart contracts all carry programs by design. The LangSec papers treat such cases as risk accepted “with eyes open” and point to TrueType’s bytecode and Ethereum contracts as examples of the risk.211 That framing gives a designer little to work with when the requirement is real. The defensible version separates two languages. The container’s syntax should be recognised completely and cheaply before anything runs, and the embedded program should run in an interpreter with bounded resources and confined effects. The 2016 Seven Turrets paper argued that Ethereum’s gas mechanism, which assigned a cost to individual operations, “placed no limit on the complexity of program semantics”.11 A metered invocation stops when its budget runs out. That bounds one execution; it does not decide whether the computation would have terminated, and it says nothing about what the program means.
Correct parsing, wrong meaning
The technical report explicitly excludes cases where both sides decode the same message and then act differently.2 Several authentication failures covered elsewhere on this site sit there. A JWT library can parse a token perfectly and then accept an unsecured token, with "alg":"none", in a context that requires a verified signature. RFC 8725 records that some libraries would “trust this value and ‘validate’ the JWT without checking any signature”, and requires libraries to let the caller specify the supported algorithms and to use no others; the JWT article covers the cases.60 A SAML service provider can verify a correctly parsed signature and then map the identity from an unsigned element; an EverParse-validated packet can still carry a well-formed request the business logic should refuse. EverParse’s own authors describe what their guarantees buy in modest terms: they underpin message authentication and let testing “focus on interoperability and performance issues”.55 LangSec reduces one large source of ambiguity. Authorisation logic, state machines and cryptographic checks still have to be right after the parse.
The evidence is mostly case studies
The quantitative claims are of three kinds. The Seven Turrets figure of 74.5 per cent is a retrospective, counterfactual estimate, made by advocates of the remedy, of which OpenSSL bugs “would have been averted”.11 Nail offers a small survey of 16 ZIP vulnerabilities and two prototypes; the largest category in that survey, memory corruption, is the class that memory-safe implementation languages target directly.16 Microsoft reports feasibility and performance for one production deployment.17 None of the cited studies measures vulnerability rates before and after adoption.
Weird machines as vocabulary
Thomas Dullien, whose presentation on programming the weird machine the ;login: authors cite, later wrote, in a paper published in IEEE Transactions on Emerging Topics in Computing, that the LangSec community uses the term “often informally and vaguely defined, and with slightly varying meanings”.6124 His paper gives a formal definition in which a weird machine arises when a concrete implementation fails to simulate an intended abstract machine. He offers a definition of exploit that he argues better matches real-world requirements than the common practice of showing that the emergent computation is Turing-complete. He also shows two implementations of the same program, one exploitable by an attacker who can flip a single chosen bit and one provably not, the difference lying in the choice of data structures.61 That result supports the LangSec intuition that design choices change how much power an attacker can borrow. It also suggests that the useful quantity is the attacker’s control over state transitions, which the Chomsky class of the input language measures only indirectly.
Where the disagreement lies
The named authors start from different concerns. Thomson and Schinazi argue from interoperability: tolerance is acceptable when a protocol specifies the range of valid expressions and the error handling precisely, and the remedy for ambiguity is active maintenance of the specification.46 Sassaman, Patterson and Bratus argue from attack surface: be definite about what is accepted, generate the recogniser from a grammar, and keep its power low.25 King argues from program structure: parse into a type that records what was checked.52 In this article’s reading, the three positions overlap on one point, that a receiver should not repair input in ways no specification defines, and differ on how much expressive power a format may carry. Whether parsers aligned by convention, as CouchDB’s two parser paths now are, are an acceptable end state is a question these sources do not settle.
Conclusion
The formal side of language-theoretic security is sound and narrower than its slogans. Membership is decidable for every class below the recursively enumerable, so a format can always be designed for a parser that halts and either accepts or rejects. Equivalence of arbitrary descriptions is decidable for regular and deterministic context-free languages and undecidable for context-free descriptions and anything broader, so no general tool can certify that two such parsers accept the same strings, let alone return the same values. Those results support the design rule of least power. They do not account for the differentials examined here, which arose in simple formats from duplicate names, a forbidden encoding, a string terminator, tolerated malformed syntax and parsers that were different programs. The durable contribution is a working discipline: specify the language completely, keep it as weak as the job allows, validate each unit and what it depends on before acting on it, carry the parsed structure forward instead of the bytes, give every value one encoding, and treat any second parser of the same data as a liability to be removed or tested against the first. RFC 9413 narrows Postel’s principle while keeping specified recovery, extensibility and active maintenance, and reaches much of the same practice from interoperability experience. What the discipline leaves open is the behaviour of programs after a correct parse, where authorisation, state and cryptographic checks still have to be got right.
Footnotes
- LANGSEC: Language-theoretic Security, project home page, langsec.org (accessed 3 December 2026). https://langsec.org/ (opens in a new tab) ↩
- Len Sassaman, Meredith L. Patterson, Sergey Bratus, Michael E. Locasto and Anna Shubina, “Security Applications of Formal Language Theory”, Dartmouth Computer Science Technical Report TR2011-709, 25 November 2011 (published in IEEE Systems Journal 7(3), September 2013). https://langsec.org/papers/langsec-tr.pdf (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13 ↩14 ↩15 ↩16 ↩17 ↩18 ↩19 ↩20 ↩21 ↩22 ↩23 ↩24
- Roy Fielding, Mark Nottingham and Julian Reschke (eds.), “HTTP/1.1”, RFC 9112, June 2022, sections 6.3 and 11.2. https://www.rfc-editor.org/rfc/rfc9112 (opens in a new tab) ↩1 ↩2
- MITRE, “CWE-22: Improper Limitation of a Pathname to a Restricted Directory”, Common Weakness Enumeration, version 5.0 (accessed 3 December 2026). https://cwe.mitre.org/data/definitions/22.html (opens in a new tab) ↩
- W3C, “XML Signature Best Practices”, Working Group Note, 11 April 2013, section 3.1.5 and Best Practice 14. https://www.w3.org/TR/xmldsig-bestpractices/ (opens in a new tab) ↩
- Noam Chomsky, “On Certain Formal Properties of Grammars”, Information and Control, 1959, Theorems 6 and 7. https://terpconnect.umd.edu/~pietro/fall2020e/Chomsky_1959%20On%20Certain%20Formal%20Properties%20of%20Grammars.pdf (opens in a new tab) ↩
- Len Sassaman, Meredith L. Patterson, Sergey Bratus and Anna Shubina, “The Halting Problems of Network Stack Insecurity”, ;login: The USENIX Magazine 36(6), December 2011. https://langsec.org/papers/Sassaman.pdf (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5
- ACM SIGACT, “2002 Gödel Prize: Géraud Sénizergues”, citation for “L(A)=L(B)? Decidability results from complete formal systems”, Theoretical Computer Science 251 (2001), pp. 1-166. https://sigact.org/prizes/g%C3%B6del/2002.html (opens in a new tab) ↩1 ↩2
- Donald E. Knuth, “On the Translation of Languages from Left to Right”, Information and Control 8, 1965, pp. 607-639. https://harrymoreno.com/assets/greatPapersInCompSci/2.5_-_On_the_translation_of_languages_from_left_to_right-Donald_E._Knuth.pdf (opens in a new tab) ↩1 ↩2 ↩3
- Tim Berners-Lee and Noah Mendelsohn (eds.), “The Rule of Least Power”, W3C TAG Finding, 23 February 2006. https://www.w3.org/2001/tag/doc/leastPower.html (opens in a new tab) ↩
- Falcon Darkstar Momot, Sergey Bratus, Sven M. Hallberg and Meredith L. Patterson, “The Seven Turrets of Babel: A Taxonomy of LangSec Errors and How to Expunge Them”, IEEE SecDev 2016, November 2016. https://langsec.org/papers/langsec-cwes-secdev2016.pdf (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 ↩13 ↩14 ↩15 ↩16 ↩17 ↩18 ↩19
- Géraud Sénizergues, “L(A)=L(B)? decidability results from complete formal systems”, Theoretical Computer Science 251(1-2), 2001, pp. 1-166, doi 10.1016/S0304-3975(00)00285-1. [https://doi.org/10.1016/S0304-3975(00)00285-1](https://doi.org/10.1016/S0304-3975(00)00285-1) ↩
- Petr Jančar, “A Short Decidability Proof for DPDA Language Equivalence via First-Order Grammars”, arXiv 1010.4760 (version 4, March 2011). https://arxiv.org/abs/1010.4760 (opens in a new tab) ↩
- V. Claus and E.-R. Olderog, “Foundations of Theoretical Computer Science”, lecture notes translated by Ievgeniia Karashchuk, University of Freiburg, section 6, Theorem 6.7. https://ac.informatik.uni-freiburg.de/teaching/ws16_17/tcs/lecturenotes.pdf (opens in a new tab) ↩
- Kathleen Moriarty (ed.) et al., “PKCS #1: RSA Cryptography Specifications Version 2.2”, RFC 8017, November 2016, section 9.2. https://www.rfc-editor.org/rfc/rfc8017 (opens in a new tab) ↩
- Julian Bangert and Nickolai Zeldovich, “Nail: A Practical Tool for Parsing and Generating Data Formats”, 11th USENIX Symposium on Operating Systems Design and Implementation (OSDI 2014). https://people.csail.mit.edu/nickolai/papers/bangert-nail.pdf (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5 ↩6
- Tahina Ramananandro, Aseem Rastogi and Nikhil Swamy, “EverParse: Hardening critical attack surfaces with formally proven message parsers”, Microsoft Research Blog, 3 May 2021. https://www.microsoft.com/en-us/research/blog/everparse-hardening-critical-attack-surfaces-with-formally-proven-message-parsers/ (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5
- Sergey Bratus, Lars Hermerschmidt, Sven M. Hallberg, Michael E. Locasto, Falcon D. Momot, Meredith L. Patterson and Anna Shubina, “Curing the Vulnerable Parser: Design Patterns for Secure Input Handling”, ;login: The USENIX Magazine, Spring 2017. https://langsec.org/papers/curing-the-vulnerable-parser.pdf (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8
- Robin Seggelmann, Michael Tuexen and Michael Williams, “Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS) Heartbeat Extension”, RFC 6520, February 2012, section 4. https://www.rfc-editor.org/rfc/rfc6520 (opens in a new tab) ↩1 ↩2
- Carl Gould, Zhendong Su and Premkumar Devanbu, “Static Checking of Dynamically Generated Queries in Database Applications”, 26th International Conference on Software Engineering (ICSE 2004), section 2.1 and footnote 2. https://www.cs.ucdavis.edu/~su/icse.pdf (opens in a new tab) ↩
- PostgreSQL Wiki, “8.1.4 et al. Security Release Technical Info” (CVE-2006-2313 and CVE-2006-2314). https://wiki.postgresql.org/wiki/8.1.4_et._al._Security_Release_Technical_Info (opens in a new tab) ↩
- Dan Kaminsky, Len Sassaman and Meredith Patterson, “PKI Layer Cake: New Collision Attacks Against The Global X.509 CA Infrastructure”, version 1.8, IOActive, 5 August 2009 (published at Financial Cryptography 2010). https://ioactive.com/wp-content/uploads/pdfs/PKILayerCake.pdf (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5 ↩6
- Dan Kaminsky, Meredith L. Patterson and Len Sassaman, “PKI Layer Cake: New Collision Attacks Against the Global X.509 Infrastructure”, Financial Cryptography and Data Security 2010 (proceedings version, KU Leuven COSIC repository). https://cosicdatabase.esat.kuleuven.be/backend/publications/files/conferencepaper/1432 (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5
- Sergey Bratus, Michael E. Locasto, Meredith L. Patterson, Len Sassaman and Anna Shubina, “Exploit Programming: From Buffer Overflows to ‘Weird Machines’ and Theory of Computation”, ;login: The USENIX Magazine 36(6), December 2011. https://langsec.org/papers/Bratus.pdf (opens in a new tab) ↩1 ↩2
- Len Sassaman, Meredith L. Patterson and Sergey Bratus, “A Patch for Postel’s Robustness Principle”, IEEE Security & Privacy, March/April 2012. https://langsec.org/papers/postel-patch.pdf (opens in a new tab) ↩1 ↩2 ↩3
- David Cooper et al., “Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile”, RFC 5280, May 2008, sections 4.1.2.4 and 4.2.1.6. https://www.rfc-editor.org/rfc/rfc5280 (opens in a new tab) ↩1 ↩2
- ITU-T, Recommendation X.690, “ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER)”, July 2002, clause 8.19.2. https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf (opens in a new tab) ↩1 ↩2 ↩3
- P. Saint-Andre and R. Salz, “Service Identity in TLS”, RFC 9525, November 2023, section 2. https://www.rfc-editor.org/rfc/rfc9525 (opens in a new tab) ↩
- Mozilla Foundation, “Security Advisory 2009-42: Compromise of SSL-protected communication”, 1 August 2009. https://www.mozilla.org/en-US/security/advisories/mfsa2009-42/ (opens in a new tab) ↩
- CVE Program, “CVE-2009-2408”, CVE record, published 30 July 2009. https://www.cve.org/CVERecord?id=CVE-2009-2408 (opens in a new tab) ↩
- Jay Freeman (saurik), “Exploit (& Fix) Android ‘Master Key’”, saurik.com, 2013. http://www.saurik.com/id/17 (opens in a new tab) ↩1 ↩2 ↩3 ↩4
- CVE Program, “CVE-2013-4787”, CVE record, published 9 July 2013. https://www.cve.org/CVERecord?id=CVE-2013-4787 (opens in a new tab) ↩
- Max Justicz, “Remote Code Execution in CouchDB”, 14 November 2017. https://justi.cz/security/2017/11/14/couchdb-rce-npm.html (opens in a new tab) ↩1 ↩2
- Apache CouchDB, “CVE-2017-12635: Apache CouchDB Remote Privilege Escalation”, security advisory, 14 November 2017. https://docs.couchdb.org/en/latest/cve/2017-12635.html (opens in a new tab) ↩1 ↩2
- Tim Bray (ed.), “The JavaScript Object Notation (JSON) Data Interchange Format”, RFC 7159, March 2014, section 4. https://www.rfc-editor.org/rfc/rfc7159 (opens in a new tab) ↩
- Tim Bray (ed.), “The JavaScript Object Notation (JSON) Data Interchange Format”, RFC 8259, December 2017, section 4. https://www.rfc-editor.org/rfc/rfc8259 (opens in a new tab) ↩
- Tim Bray (ed.), “The I-JSON Message Format”, RFC 7493, March 2015, sections 2.3 and 3. https://www.rfc-editor.org/rfc/rfc7493 (opens in a new tab) ↩1 ↩2
- Siguza, “Psychic Paper”, Siguza’s Blog, 1 May 2020. https://blog.siguza.net/psychicpaper/ (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5
- Vasco Franco, “Unexpected security footguns in Go’s parsers”, Trail of Bits Blog, 17 June 2025. https://blog.trailofbits.com/2025/06/17/unexpected-security-footguns-in-gos-parsers/ (opens in a new tab) ↩1 ↩2 ↩3
- The Go Authors, “encoding/json” package documentation for Go 1.25.0, section “Security Considerations”, pkg.go.dev. https://pkg.go.dev/encoding/json@go1.25.0#hdr-Security_Considerations (opens in a new tab) ↩
- The Go Authors, “Go 1.25 Release Notes”, go.dev. https://go.dev/doc/go1.25 (opens in a new tab) ↩
- The Go Authors, “Release History”, go.dev (go1.27.0 released 19 August 2026). https://go.dev/doc/devel/release (opens in a new tab) ↩
- The Go Authors, “Go 1.27 Release Notes”, go.dev (Go 1.27 arrived in August 2026). https://go.dev/doc/go1.27 (opens in a new tab) ↩1 ↩2
- The Go Authors, “encoding/json/v2” package documentation, pkg.go.dev. https://pkg.go.dev/encoding/json/v2 (opens in a new tab) ↩1 ↩2
- The Go Authors, “encoding/json” package documentation, sections “Security Considerations” and “Migrating to v2”, pkg.go.dev. https://pkg.go.dev/encoding/json (opens in a new tab) ↩
- Martin Thomson and David Schinazi, “Maintaining Robust Protocols”, RFC 9413 (IAB, Informational), June 2023, sections 4 and 5. https://www.rfc-editor.org/rfc/rfc9413 (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8
- Jon Postel (ed.), “DoD Standard Internet Protocol”, RFC 760, January 1980. https://www.rfc-editor.org/rfc/rfc760 (opens in a new tab) ↩
- Jon Postel (ed.), “DoD Standard Transmission Control Protocol”, RFC 761, January 1980, section 2.10. https://www.rfc-editor.org/rfc/rfc761 (opens in a new tab) ↩
- Robert Braden (ed.), “Requirements for Internet Hosts – Communication Layers”, RFC 1122, October 1989, section 1.2.2. https://www.rfc-editor.org/rfc/rfc1122 (opens in a new tab) ↩
- IETF Datatracker, “The Harmful Consequences of the Robustness Principle”, draft-thomson-postel-was-wrong-03, replaced by draft-iab-protocol-maintenance. https://datatracker.ietf.org/doc/draft-thomson-postel-was-wrong/ (opens in a new tab) ↩
- WHATWG, “HTML Living Standard: 13.2 Parsing HTML documents”, sections 13.2.1 and 13.2.2 (accessed 3 December 2026). https://html.spec.whatwg.org/multipage/parsing.html (opens in a new tab) ↩1 ↩2
- Alexis King, “Parse, don’t validate”, 5 November 2019. https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ (opens in a new tab) ↩1 ↩2 ↩3 ↩4
- Alexis King, “Names are not type safety”, 1 November 2020. https://lexi-lambda.github.io/blog/2020/11/01/names-are-not-type-safety/ (opens in a new tab) ↩
- DARPA, “SafeDocs: Safe Documents”, programme page (accessed 3 December 2026). https://www.darpa.mil/research/programs/safe-documents (opens in a new tab) ↩
- Tahina Ramananandro, Antoine Delignat-Lavaud, Cédric Fournet, Nikhil Swamy, Tej Chajed, Nadim Kobeissi and Jonathan Protzenko, “EverParse: Verified Secure Zero-Copy Parsers for Authenticated Message Formats”, 28th USENIX Security Symposium, August 2019. https://www.usenix.org/system/files/sec19-ramananandro_0.pdf (opens in a new tab) ↩1 ↩2 ↩3 ↩4 ↩5
- D. J. Bernstein, “Netstrings”, 1 February 1997. https://cr.yp.to/proto/netstrings.txt (opens in a new tab) ↩
- UpstandingHackers, “Hammer” README, GitHub. https://github.com/UpstandingHackers/hammer (opens in a new tab) ↩
- Kaitai Struct project, “Kaitai Struct: declarative binary format parsing language”, kaitai.io (accessed 3 December 2026). https://kaitai.io/ (opens in a new tab) ↩
- Kaitai Struct project, “Kaitai Struct User Guide”, sections 4.4 and 4.13. https://doc.kaitai.io/user_guide.html (opens in a new tab) ↩
- Y. Sheffer, D. Hardt and M. Jones, “JSON Web Token Best Current Practices”, RFC 8725 (BCP 225), February 2020, sections 2.1 and 3.1. https://www.rfc-editor.org/rfc/rfc8725 (opens in a new tab) ↩
- Thomas Dullien, “Weird Machines, Exploitability, and Provable Unexploitability”, IEEE Transactions on Emerging Topics in Computing 8(2), 2020, pp. 391-403, doi 10.1109/TETC.2017.2785299 (author’s preprint linked). https://cs.uwaterloo.ca/~m285xu/courses/cs858/assets/papers/weird-machine.pdf (opens in a new tab) ↩1 ↩2

SecSIG