Newshot

GitHub Actions accepts invalid YAML

Original text(via Lobsters)
  • github-actions

TL;DR: GitHub Actions accepts several invalid YAML productions, making it difficult (read: impossible) to parse some real-world action and workflow definitions with a properly conforming YAML parser.

This is related to zizmor#1116, which has been bugging me for a year and a half.

Last April, a user reported that zizmor was rejecting a workflow containing a step that looks like this:


        - name: Create NPM Remote Repository JSON
  uses: jsdaniell/[email protected]
  with:
    name: "npm-remote-template.json"
    json: '{
      "key": "npm-remote",
      "rclass": "remote",
      "packageType": "npm",
      "url": "https://registry.npmjs.org"
    }'
      

Apart from the use of a multi-line flow-style string for the json: key, nothing particularly stands out about this step.

Except: it isn't valid YAML! YAML says this about flow-style nodes that are nested inside of a block-style parent collection (read: map or array):

Flow nodes must be indented by at least one more space than the parent block collection. Note that flow nodes may begin on a following line. Source: YAML 1.2.2 § 8.2.3

Flow nodes must be indented by at least one more space than the parent block collection. Note that flow nodes may begin on a following line.

Source: YAML 1.2.2 § 8.2.3

That means the correct syntax is instead:


        - name: Create NPM Remote Repository JSON
  uses: jsdaniell/[email protected]
  with:
    name: "npm-remote-template.json"
    json: '{
      "key": "npm-remote",
      "rclass": "remote",
      "packageType": "npm",
      "url": "https://registry.npmjs.org"
     }'
      

The difference is barely visible:

YAML is a big and complicated spec, so it didn't even occur to me that this was invalid. Instead, I opened tree-sitter-yaml#36 to "fix" it. I've now opened tree-sitter-yaml#51 to revert that misbegotten fix.

On GitHub's side, I'm not sure if they have a clean path towards spec conformance here. Much of the code behind Actions is proprietary, but it seems likely that the underlying parser on their end is YamlDotNet.

Actions appears to use YamlDotNet 5.3.0, which was released in 2018. However, even upgrading to the newest version (18.1.0 as of writing) wouldn't fix this particular bug, since it's still present on that version (note the !isSingleQuoted guard).

My best guess is that a 2020 patch (YamlDotNet#467) only fixed the double-quoted form because YAML's official test suite only tests rule 8.2.3 with a double-quoted string, despite it applying to both forms.

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by Lobsters
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗