CI_RUNNER_TAGS can produce invalid JSON for valid Runner tags

Summary

CI_RUNNER_TAGS is documented as a JSON array, but Ci::Runner#predefined_variables currently constructs it using Ruby array inspection.

A Runner tag accepted by the supported Runner update API can contain a control character for which Ruby uses an escape that JSON does not recognize. For example, Ruby represents U+001B ESC as \e.

Steps to reproduce

  1. Update a Runner through PUT /api/v4/runners/:id with a tag containing U+001B:

    {
      "tag_list": ["prefix\u001bsuffix"]
    }
  2. Configure a job to require the same tag.

  3. Parse the job's CI_RUNNER_TAGS value with a standards-compliant JSON parser.

The GitLab-side reproduction verified the supported update request, exact persistence, Ci::Runner#matches_build?, predefined-variable generation, and Runner job-response transport. It did not launch an external Runner process.

Current behavior

The request succeeds and persists the exact tag, but the variable contains a Ruby-only escape:

persisted tag: "prefix\esuffix"
codepoints: [112, 114, 101, 102, 105, 120, 27, 115, 117, 102, 102, 105, 120]
CI_RUNNER_TAGS: ["prefix\esuffix"]
parse result: JSON::ParserError

The outer job-response JSON remains valid because it transports the variable value as an escaped string. The logical CI_RUNNER_TAGS value itself is not valid JSON.

Expected behavior

CI_RUNNER_TAGS should always be valid JSON and parse back to the Runner's configured tag strings.

Impact

Jobs that parse the variable according to its documented JSON contract can fail for affected valid Runner tags. Ordinary tags are not inherently affected.

Root cause

Ci::Runner#predefined_variables uses Ruby array inspection to construct a variable documented as JSON. Ruby and JSON escape grammars differ for supported control characters.

Historical context

!179671 (merged) correctly restored the established ordinary representation such as ["docker", "ruby"]. This issue concerns a narrower escaping gap: Ruby's inspection grammar is not always valid JSON.

#384949 (closed) records the earlier comma-separated versus array-format transition. It does not cover this supported-control-character parse failure.

Affected versions

  • Fresh master at f8c963f81fb0d7c50c750c3d4e89904f815ceaf7: dynamically reproduced.
  • Latest stable v19.4.0-ee: statically contains the same implementation and JSON documentation.
  • Git history shows the current JSON contract and affected implementation together by v17.9.0-ee.

AI assistance

AI tooling was used to assist with investigation and drafting. The contributor independently reviewed the implementation, reproduced the bug locally, verified the regression test and fix, and takes responsibility for the submitted changes.

Edited by Whale Tech