Alex’s notes

Software, useful tools, and making things.

Invalid YAML, Green Checkmark

William Woodruff spent a year and a half with a bug report he couldn’t close. A user’s workflow ran fine on GitHub, and zizmor, his workflow auditing tool, refused to parse it. On Sunday he wrote up why: the file isn’t YAML, and GitHub runs it anyway.

I think he’s right to put the strict parser back. I also think the most interesting part is one he didn’t test, because when I ran his example through the parsers on my laptop, GitHub turned out to have company.

One space

The whole bug fits in a step’s with: block. A JSON blob in a single quoted string, spread over several lines, with the closing brace lined up under the key:

with:
  json: '{
    "key": "npm-remote"
  }'

YAML 1.2.2, section 8.2.3 says a flow node nested inside a block collection has to be indented at least one space more than its parent. That closing }' sits in the same column as json:, so it belongs to the mapping, and the string never properly ends. The valid version moves the brace one column to the right. That is the entire diff.

Woodruff’s reaction is the most honest sentence in the post: “YAML is a big and complicated spec, so it didn’t even occur to me that this was invalid.” Same here. I have written YAML for longer than I’d like to admit, and I would have approved that step in review without a second look. It looks like every JSON blob anyone has ever pasted into a config file.

His digging found that Actions appears to parse with YamlDotNet 5.3.0, a release from 2018, and that even the current version still lets this through. A 2020 patch fixed the rule for double quoted strings only. His best guess is that YAML’s official test suite only checks this rule with a double quoted string, so the single quoted form slipped past everyone who graded themselves against it.

So I tried two other parsers

I wrote the snippet out three ways (single quoted and misindented, double quoted and misindented, single quoted and correct) and fed them to what was already installed: Ruby’s Psych, which wraps the C library libyaml, and the yaml package for JavaScript that my blog’s build happens to pull in. Ruby 4.0.5 with Psych 5.3.1 on libyaml 0.2.5, Node 24.21.0 with yaml 2.9.1, on an M4 Pro Mac.

bad.yml (single quoted, misindented)
  libyaml 0.2.5   ok "{ \"key\": \"npm-remote\" }"
  yaml 2.9.1      YAMLParseError: Missing closing 'quote at line 5, column 28

bad_dq.yml (double quoted, misindented)
  libyaml 0.2.5   Psych::SyntaxError: did not find expected key while parsing a block mapping at line 4 column 7
  yaml 2.9.1      YAMLParseError: Nested mappings are not allowed in compact mappings at line 4, column 13

good.yml (single quoted, indented one more space)
  libyaml 0.2.5   ok "{ \"key\": \"npm-remote\" }"
  yaml 2.9.1      ok "{ \"key\": \"npm-remote\" }"

libyaml has exactly the same asymmetry as YamlDotNet. It rejects the double quoted mistake and happily accepts the single quoted one. Different language, different authors, same hole. That fits Woodruff’s guess about the test suite rather nicely, though I didn’t read libyaml’s scanner, so fitting is all I’ll claim. What it does mean is that “valid YAML” in practice is decided by which parser you picked. One strict implementation out of three is a vote you lose.

Postel wrote this bug

Be liberal in what you accept is the oldest advice in our trade, and this is where it goes when nobody is watching. In 2023 the IAB published RFC 9413, by Martin Thomson and David Schinazi, which says the reading of the robustness principle that tolerates unexpected input is “no longer considered best practice in all scenarios.” The RFC also spells out the mechanism: once existing implementations tolerate a deviation, any newer implementation has a strong incentive to tolerate it too, or it won’t work anywhere.

zizmor is the newer implementation. A security linter that can’t parse a workflow audits nothing in it, so every one of these files is a blind spot until the tool learns to accept what GitHub accepts. Woodruff did exactly that, with a change to the YAML grammar his tool parses with, and he has now opened the revert. The RFC predicted the first move. The second takes more nerve.

I have lived the quiet version of this. Years ago I looked after a deploy pipeline where one config file was read by two programs: the deployer, and a checker a colleague wrote so reviewers could see what a change would do. For eight months they disagreed about one file. Nobody noticed, because the checker failed quietly and printed nothing, and an empty diff looks exactly like a safe change. When we finally found it, production had been running a setting the review tool had never once shown anybody.

The case for the quirk

The strongest argument against me is the web. Browsers were lenient about broken HTML for a decade, and the fix was not strictness. The WHATWG parsing spec defines the rules for HTML documents “whether they are syntactically correct or not,” and it then spells out exactly what a parser does at every one of those errors. The leniency became the standard, and now every browser builds the same tree from the same broken markup. By that logic GitHub’s YAML is a dialect, zizmor should implement it, and the spec should catch up.

Woodruff himself gave the second half of that argument in the Lobsters thread: “Historically GitHub has shown great hesitance when it comes to breaking Actions, even when it would make the ecosystem more correct as a whole.” So the quirk is permanent. Tools may as well accept it.

Fair. Here is what survives. HTML got there because people spent years turning the leniency into an algorithm, with test cases, that anyone could implement. GitHub’s parser is closed, pinned to a 2018 library, and nobody has written its behaviour down. A tolerance you can’t read is not a dialect yet. You can only reproduce it by trial and error, and then you’re bug compatible with a binary you’ve never seen, which is a promise to keep doing that every time GitHub’s parser changes.

What I’d ship

Keep the parser strict, and turn the failure into a finding. Not a crash, and certainly not silence: a message with the line number saying this file is invalid YAML that GitHub happens to run, and that moving the brace one column right makes it valid everywhere. The user who filed the original issue would have fixed it in ten seconds with that message. The checker at my old job would have saved us eight months with any message at all.

My rule for my own tools is the same. I’ll tolerate a quirk when I can name it, test it and point at where it’s written down. Everything else gets reported to the person who can fix it, which in this case is whoever typed the brace.

Comments