Two Correct RFC Implementations That Still Can't Talk
A Go service sends the JSON {"id": 9007199254740993}. A JavaScript client reads it and gets 9007199254740992. Both are following RFC 8259 to the letter, and the ID is now wrong by one.
Nobody has a bug here, by the standard's own definition. That is the uncomfortable part: "conforms to the RFC" and "interoperates" are two different properties, and the gap between them is where a lot of production breakage lives.
The spec said you may, and you both did
RFC 8259 says a JSON number is just a sequence of digits. It places no limit on size or precision. It then adds, in the section on numbers, that implementations may set limits, and that software which reads numbers as IEEE 754 doubles will interoperate with everyone else only within that range.
So the grammar permits your ID, and the JavaScript runtime is entitled to turn it into a double. Here is the Go side of the same trap:
package main
import (
"encoding/json"
"fmt"
"strings"
)
func main() {
in := `{"id": 9007199254740993}`
var loose map[string]any
if err := json.Unmarshal([]byte(in), &loose); err != nil {
panic(err)
}
fmt.Printf("%.0f\n", loose["id"].(float64)) // 9007199254740992
dec := json.NewDecoder(strings.NewReader(in))
dec.UseNumber()
var exact map[string]any
if err := dec.Decode(&exact); err != nil {
panic(err)
}
fmt.Println(exact["id"]) // 9007199254740993
}
Decoding into any gives you a float64, so Go does the same thing the browser does. Decoding into an int64 field, or using UseNumber, keeps the digits. The wire format was never the problem; the two ends disagreed about what a number is.
The practical fix is to send large identifiers as strings. That is why so many public APIs do exactly that.
Four ways a correct implementation breaks a peer
The JSON case is one member of a small family. Most interoperability failures I have seen fit one of these:
- The spec leaves a choice open (MAY, SHOULD, "implementation-defined"), and the two sides chose differently.
- The spec is silent about an edge case, so each side filled the gap with whatever its parser did naturally.
- One side is strict and the other is lenient, so the lenient side sends something the strict side rightly rejects.
- A third party sits in the middle (a proxy, a firewall, a "security" appliance) and has its own opinion about the protocol.
Duplicate keys and who gets the last word
The same RFC says object member names SHOULD be unique, and that when they are not, receiving software behaves unpredictably. Many parsers take the last value; some take the first; some keep both.
That sounds harmless until a gateway validates the first "role" and the backend acts on the last one. Each parser is within the standard, and the combination is an authorisation bypass. SMTP has a nastier cousin of this, which is worth a quick detour.
Quick detour: SMTP smuggling
An SMTP message ends with <CR><LF>.<CR><LF>. Some servers also accept a bare <LF> where <CR><LF> belongs, because being liberal is traditional. In 2023 researchers showed that when an outbound server and an inbound server disagree about whether <LF>.<CR><LF> ends the data, an attacker can hide a second message inside the first and send mail that appears to come from someone else.
Hang on, why does that work? Because the sender thinks the dot sequence is ordinary content, so it does not stop the message there. The receiver thinks it is the terminator and treats what follows as a fresh command. Two parsers, one byte stream, two different message boundaries.
When the network has opinions
TLS 1.3 is the best-known example of a protocol bending around third parties. Early drafts broke on a worrying number of real networks, because middleboxes had hard-coded what a handshake looked like. The final design in RFC 8446 therefore makes a TLS 1.3 ClientHello look much like a TLS 1.2 one: the real version moves into an extension, and there is an optional compatibility mode that sends a dummy session ID and a fake change-cipher-spec record.
None of that is elegant. It exists because the spec alone was not enough; the deployed network had to be accommodated.
The counter-move is GREASE (RFC 8701). Clients deliberately advertise reserved, meaningless values for cipher suites, extensions and so on, so that servers which choke on unknown values break immediately instead of years later. It is a deliberate test for the "unknown input" assumption.
What to do about it in your own code
- Test against at least one other implementation, ideally two that were written independently. Self-interop proves only that you agree with yourself.
- List the MAY and SHOULD clauses in the RFC and write down which way you went. Those are your likely mismatch points.
- Be strict about what you send and decide deliberately what to do with what you receive. Rejecting ambiguous input is often safer than guessing.
- Put hostile and odd cases in your tests: huge numbers, duplicate fields, bare line feeds, unknown extensions.
- Where a gateway and a backend both parse the same input, make them share one parser or normalise once at the edge.
The RFC is a contract, but it is a contract written by committee, with deliberate gaps where the committee could not agree. Your peer's reading of those gaps is data you have to collect, not something you can derive.