@natjswenson/shipflow 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SKILL.md CHANGED
@@ -115,6 +115,7 @@ This is a **separate, later invocation** from the one that ran the promotion's `
115
115
  - All `gh`/`git` invocations in the CLI are argv-style (`spawnSync` with an args array, no shell) — never construct a shell command string from user input when extending this skill.
116
116
  - `.github/shipflow.json` is committed policy, not secrets — never write credential *values* into it, only the *name* of a secret (`release.releaseCredential`).
117
117
  - Never write shipflow's config anywhere other than `.github/shipflow.json` in the target repo.
118
+ - **`renderTemplate` validates every substituted value before writing YAML, and this must never be weakened.** `config.branches.dev`/`main` and `release.releaseCredential` are editable by anyone with repo *write* access (not just the admin who ran setup), yet they land in single-quoted YAML string comparisons and a `${{ secrets.X }}` expression with pure string substitution. An unvalidated branch name containing a quote (e.g. `dev' || 'x'=='x`) makes the auto-merge job's `if:` condition unconditionally true — auto-merge would enable on *any* PR to main, not just genuine dev-branch promotions; a value containing a newline can inject arbitrary new YAML steps into the committed, then-executed workflow. If you add a new substitution token, it needs a validator in `TOKEN_VALIDATORS` before it ships — never assume a config field is pre-sanitized.
118
119
 
119
120
  ## Edge cases
120
121
 
package/bin/shipflow.js CHANGED
@@ -85,7 +85,12 @@ function cmdPlan(args) {
85
85
  releaseCredentialName: config.release?.releaseCredential ?? null,
86
86
  });
87
87
  const templateSource = readFileSync(TEMPLATE_PATH, 'utf8');
88
- const plan = computePlan(repoState, config, templateSource);
88
+ let plan;
89
+ try {
90
+ plan = computePlan(repoState, config, templateSource);
91
+ } catch (e) {
92
+ return fail(`plan: ${e.message}`);
93
+ }
89
94
  printJson({ plan, stateHash: repoState.stateHash });
90
95
  }
91
96
 
@@ -122,7 +127,12 @@ function cmdApply(args) {
122
127
  releaseCredentialName: config.release?.releaseCredential ?? null,
123
128
  });
124
129
  const templateSource = readFileSync(TEMPLATE_PATH, 'utf8');
125
- const plan = computePlan(repoState, config, templateSource);
130
+ let plan;
131
+ try {
132
+ plan = computePlan(repoState, config, templateSource);
133
+ } catch (e) {
134
+ return fail(`apply: ${e.message}`);
135
+ }
126
136
 
127
137
  // The CLI-level TOCTOU gate: compare the freshly-detected state against
128
138
  // what the user confirmed at plan time (--expect-state-hash, captured
package/lib/render.mjs CHANGED
@@ -14,6 +14,34 @@
14
14
 
15
15
  const TOKEN_RE = /\{\{(\w+)\}\}/g;
16
16
 
17
+ // DEV_BRANCH/MAIN_BRANCH land inside single-quoted YAML string comparisons
18
+ // (`... == '{{DEV_BRANCH}}'`) and RELEASE_CREDENTIAL_SECRET lands inside a
19
+ // `${{ secrets.X }}` GitHub Actions expression — this function does pure
20
+ // string substitution with NO awareness of YAML or GHA-expression grammar,
21
+ // so any of these three params can break out of their quoting context if
22
+ // not validated first. Concretely: devBranch = "dev' || 'x'=='x" renders
23
+ // the auto-merge job's `if:` condition to `... == 'dev' || 'x'=='x'`,
24
+ // which is unconditionally true — enabling auto-merge on ANY pull request
25
+ // to main, not just genuine dev-branch promotions. A value containing a
26
+ // newline in any of the three can inject entirely new YAML keys/steps into
27
+ // the committed, then-executed workflow file. This is not a theoretical
28
+ // input: config.branches.{main,dev} and config.release.releaseCredential
29
+ // come from .github/shipflow.json, a file anyone with repo WRITE access
30
+ // (not just the admin who ran shipflow's setup) can edit — a strictly
31
+ // lower trust level than the admin-scoped `gh` credential the rendered
32
+ // workflow runs with. Found via a Siege security audit (2026-07-15).
33
+ const UNSAFE_YAML_STRING_RE = /['\r\n]/;
34
+ // GitHub Actions secret names: letters, digits, underscore; cannot start
35
+ // with a digit (case-insensitivity aside, this is the full safe charset).
36
+ const SAFE_SECRET_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
37
+
38
+ const TOKEN_VALIDATORS = Object.freeze({
39
+ DEV_BRANCH: (v) => !UNSAFE_YAML_STRING_RE.test(v),
40
+ MAIN_BRANCH: (v) => !UNSAFE_YAML_STRING_RE.test(v),
41
+ MERGE_FLAG: () => true, // closed enum from mergeMethodToFlag — never attacker-shaped
42
+ RELEASE_CREDENTIAL_SECRET: (v) => SAFE_SECRET_NAME_RE.test(v),
43
+ });
44
+
17
45
  // params: { devBranch, mainBranch, mergeFlag, releaseCredentialSecret }
18
46
  // mergeFlag is one of "--merge" | "--squash" | "--rebase", derived from
19
47
  // config.mergeMethod.devToMainMethod by the caller (not this function —
@@ -22,17 +50,28 @@ const TOKEN_RE = /\{\{(\w+)\}\}/g;
22
50
  // config shape, only of the template's token names).
23
51
  export function renderTemplate(templateSource, params) {
24
52
  const missing = [];
53
+ const unsafe = [];
25
54
  const rendered = templateSource.replace(TOKEN_RE, (_, name) => {
26
55
  const key = TOKEN_TO_PARAM[name];
27
56
  if (!key || !(key in params)) {
28
57
  missing.push(name);
29
58
  return `{{${name}}}`;
30
59
  }
31
- return String(params[key]);
60
+ const value = String(params[key]);
61
+ const validate = TOKEN_VALIDATORS[name];
62
+ if (validate && !validate(value)) {
63
+ unsafe.push(name);
64
+ }
65
+ return value;
32
66
  });
33
67
  if (missing.length > 0) {
34
68
  throw new Error(`renderTemplate: missing param(s) for token(s): ${missing.join(', ')}`);
35
69
  }
70
+ if (unsafe.length > 0) {
71
+ throw new Error(
72
+ `renderTemplate: unsafe value for token(s): ${unsafe.join(', ')} — branch names must not contain a quote or newline, and the release-credential secret name must match GitHub's secret-naming rules (letters/digits/underscore, not starting with a digit)`
73
+ );
74
+ }
36
75
  return rendered;
37
76
  }
38
77
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@natjswenson/shipflow",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Scaffold a configurable dev/main branching, auto-merge, branch-cleanup, and release-tagging workflow into any repo",
5
5
  "license": "MIT",
6
6
  "author": "Nate Swenson",
@@ -60,6 +60,11 @@
60
60
  "id": "release-credential-never-github-token",
61
61
  "pattern": "never default it to `GITHUB_TOKEN`",
62
62
  "rationale": "Found by dogfooding on claude-skills itself (2026-07-15): a PR auto-merged under secrets.GITHUB_TOKEN completes attributed to github-actions[bot], and GitHub's loop-prevention rule means that bot-attributed merge's pull_request:closed event never triggers label-release-pending — the entire manual-gate release-ask flow silently never has anything to find unless releaseCredential names a real PAT."
63
+ },
64
+ {
65
+ "id": "render-template-validates-substitutions",
66
+ "pattern": "never assume a config field is pre-sanitized",
67
+ "rationale": "Found by a Siege security audit (2026-07-15): renderTemplate did pure string substitution with zero escaping, so a repo-write-level (not admin-level) edit to .github/shipflow.json's branch names or release.releaseCredential could break out of the rendered YAML's quoting and make the auto-merge job's if: condition unconditionally true, or inject arbitrary new workflow steps — a privilege escalation via the credential the rendered workflow runs with."
63
68
  }
64
69
  ],
65
70
  "cli_commands_referenced": ["detect", "plan", "apply", "releases", "release-dispatch", "rename-default-branch"]