Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Close runner output alias bypasses

pulse-triage[bot]4f7a3d0006e5
diff --git a/.github/workflows/README.md b/.github/workflows/README.md
index 279c2c245e..17b1bd4844 100644
--- a/.github/workflows/README.md
+++ b/.github/workflows/README.md
@@ -44,10 +44,13 @@ would turn their value back into shell source.
Passing data through `env` does not make it safe to append to the runner's
`GITHUB_OUTPUT`, `GITHUB_ENV`, `GITHUB_PATH`, or `GITHUB_STATE` command files.
-The audit rejects direct writes of workflow data and values read from the event
-payload; a step must first constrain the value to its exact one-line grammar or
-encode it with the command-file multiline protocol. This prevents embedded
-newlines from creating additional outputs or environment entries.
+The audit follows workflow data and values read from the event payload through
+local Bash and PowerShell assignments before rejecting command-file writes, so
+renaming a value is not mistaken for validation. Use
+`scripts/write_github_output.py` for output data: it validates the output name
+and chooses a random multiline delimiter that cannot collide with the value.
+This prevents embedded newlines from creating additional outputs or
+environment entries.
Workflows triggered by `pull_request` cannot reference confidential repository
secrets. Canonical governance therefore keeps its pull-request checks local to
diff --git a/.github/workflows/build-release-candidate.yml b/.github/workflows/build-release-candidate.yml
index 91a8223ae2..516c7f93f3 100644
--- a/.github/workflows/build-release-candidate.yml
+++ b/.github/workflows/build-release-candidate.yml
@@ -93,6 +93,11 @@ jobs:
secure_runtime_artifact_digest: ${{ steps.wait.outputs.secure_runtime_artifact_digest }}
secure_runtime_artifact_name: ${{ steps.wait.outputs.secure_runtime_artifact_name }}
steps:
+ - name: Checkout payload coordination control
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
- name: Dispatch exact-SHA compiler workflow
id: dispatch
env:
@@ -177,7 +182,7 @@ jobs:
artifact_digest="$(jq -er '.digest | select(test("^sha256:[0-9a-f]{64}$")) | sub("^sha256:"; "")' <<<"${artifact_json}")"
echo "artifact_id=${artifact_id}" >> "$GITHUB_OUTPUT"
echo "artifact_digest=${artifact_digest}" >> "$GITHUB_OUTPUT"
- echo "artifact_name=${artifact_name}" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py artifact_name "${artifact_name}"
secure_runtime_artifact_name="secure-runtime-qualification-${SOURCE_SHA}-${VERSION}-${REQUEST_ID}"
secure_runtime_artifact_json="$(jq -ce \
@@ -188,7 +193,7 @@ jobs:
secure_runtime_artifact_digest="$(jq -er '.digest | select(test("^sha256:[0-9a-f]{64}$")) | sub("^sha256:"; "")' <<<"${secure_runtime_artifact_json}")"
echo "secure_runtime_artifact_id=${secure_runtime_artifact_id}" >> "$GITHUB_OUTPUT"
echo "secure_runtime_artifact_digest=${secure_runtime_artifact_digest}" >> "$GITHUB_OUTPUT"
- echo "secure_runtime_artifact_name=${secure_runtime_artifact_name}" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py secure_runtime_artifact_name "${secure_runtime_artifact_name}"
signing-configuration:
name: Verify Native Signing Configuration
@@ -515,6 +520,11 @@ jobs:
outputs:
signing_backend: ${{ steps.evidence.outputs.signing_backend }}
steps:
+ - name: Checkout signing collection control
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
- name: Download legacy signed binaries
if: ${{ inputs.windows_signing_backend == 'legacy-pfx' }}
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
@@ -627,7 +637,7 @@ jobs:
$evidence | ConvertTo-Json -Depth 6 | Set-Content windows-signing-evidence.json -Encoding utf8NoBOM
if ($env:WINDOWS_SIGNING_BACKEND -notin @('signpath', 'legacy-pfx')) { throw "Invalid Windows signing backend." }
$validatedBackend = $env:WINDOWS_SIGNING_BACKEND
- "signing_backend=$validatedBackend" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
+ python scripts/write_github_output.py signing_backend $validatedBackend
- name: Upload signed Windows binaries
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
@@ -662,6 +672,12 @@ jobs:
manifest_artifact_name: ${{ steps.identity.outputs.manifest_artifact_name }}
container_artifact_name: ${{ steps.identity.outputs.container_artifact_name }}
steps:
+ - name: Checkout repository
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ fetch-depth: 0
+
- name: Resolve candidate identity
id: identity
env:
@@ -673,15 +689,9 @@ jobs:
exit 1
fi
validated_version="${VERSION}"
- echo "artifact_name=release-candidate-${GITHUB_SHA}-${validated_version}" >> "$GITHUB_OUTPUT"
- echo "manifest_artifact_name=release-candidate-manifest-${GITHUB_SHA}-${validated_version}" >> "$GITHUB_OUTPUT"
- echo "container_artifact_name=release-container-payload-${GITHUB_SHA}-${validated_version}" >> "$GITHUB_OUTPUT"
-
- - name: Checkout repository
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- with:
- persist-credentials: false
- fetch-depth: 0
+ python3 scripts/write_github_output.py artifact_name "release-candidate-${GITHUB_SHA}-${validated_version}"
+ python3 scripts/write_github_output.py manifest_artifact_name "release-candidate-manifest-${GITHUB_SHA}-${validated_version}"
+ python3 scripts/write_github_output.py container_artifact_name "release-container-payload-${GITHUB_SHA}-${validated_version}"
- name: Validate candidate identity
env:
diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml
index 18bbf4b78d..fca418974b 100644
--- a/.github/workflows/create-release.yml
+++ b/.github/workflows/create-release.yml
@@ -108,6 +108,12 @@ jobs:
visual_capture_count: ${{ steps.visual_plan.outputs.capture_count }}
visual_comparison_tag: ${{ steps.visual_plan.outputs.comparison_tag }}
steps:
+ - name: Checkout repository
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ fetch-depth: 0
+
- name: Extract version
id: extract
env:
@@ -140,19 +146,13 @@ jobs:
SOURCE_BRANCH="${GITHUB_REF_NAME}"
HISTORICAL_ASSET_BACKFILL_ONLY="${HISTORICAL_ASSET_BACKFILL_INPUT}"
- echo "tag=${TAG}" >> $GITHUB_OUTPUT
- echo "version=${VERSION}" >> $GITHUB_OUTPUT
+ python3 scripts/write_github_output.py tag "${TAG}"
+ python3 scripts/write_github_output.py version "${VERSION}"
echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT
echo "source_branch=${SOURCE_BRANCH}" >> $GITHUB_OUTPUT
- echo "historical_asset_backfill_only=${HISTORICAL_ASSET_BACKFILL_ONLY}" >> $GITHUB_OUTPUT
+ python3 scripts/write_github_output.py historical_asset_backfill_only "${HISTORICAL_ASSET_BACKFILL_ONLY}"
echo "Version: ${VERSION}, Tag: ${TAG}, Prerelease: ${IS_PRERELEASE}, Branch: ${SOURCE_BRANCH}, HistoricalBackfillOnly: ${HISTORICAL_ASSET_BACKFILL_ONLY}"
- - name: Checkout repository
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- with:
- persist-credentials: false
- fetch-depth: 0
-
- name: Resolve required release branch
id: branch_policy
env:
@@ -164,7 +164,7 @@ jobs:
echo "::error::Invalid release line. Version ${WORKFLOW_OUTPUT_1} must run from ${REQUIRED_BRANCH}, but workflow ref is ${WORKFLOW_OUTPUT_2}."
exit 1
fi
- echo "required_branch=${REQUIRED_BRANCH}" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py required_branch "${REQUIRED_BRANCH}"
echo "[OK] Governed release branch for ${WORKFLOW_OUTPUT_1} is ${REQUIRED_BRANCH}"
- name: Validate release-note visual plan
@@ -956,11 +956,11 @@ jobs:
RELEASE_PUBLISHED_AT=$(echo "$EXISTING_RELEASE" | jq -r '.published_at // empty')
RELEASE_ACTIVATION_COMMITTED=$(echo "$EXISTING_RELEASE" | jq -r 'any(.assets[]?; .name == "release-activation.json")')
- echo "release_id=${RELEASE_ID}" >> $GITHUB_OUTPUT
- echo "release_url=${RELEASE_URL}" >> $GITHUB_OUTPUT
- echo "release_is_draft=${RELEASE_IS_DRAFT}" >> $GITHUB_OUTPUT
- echo "release_published_at=${RELEASE_PUBLISHED_AT}" >> $GITHUB_OUTPUT
- echo "release_activation_committed=${RELEASE_ACTIVATION_COMMITTED}" >> $GITHUB_OUTPUT
+ python3 scripts/write_github_output.py release_id "${RELEASE_ID}"
+ python3 scripts/write_github_output.py release_url "${RELEASE_URL}"
+ python3 scripts/write_github_output.py release_is_draft "${RELEASE_IS_DRAFT}"
+ python3 scripts/write_github_output.py release_published_at "${RELEASE_PUBLISHED_AT}"
+ python3 scripts/write_github_output.py release_activation_committed "${RELEASE_ACTIVATION_COMMITTED}"
- name: Create tag
env:
@@ -1507,6 +1507,11 @@ jobs:
outputs:
r2_prefix: ${{ steps.publish.outputs.r2_prefix }}
steps:
+ - name: Checkout private-runtime staging control
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
- name: Dispatch and verify private Pro runtime staging
id: publish
env:
@@ -1584,7 +1589,7 @@ jobs:
exit 1
fi
r2_prefix="${TAG}-pro-${run_created_date}-${GITHUB_RUN_ID}"
- echo "r2_prefix=${r2_prefix}" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py r2_prefix "${r2_prefix}"
echo "Dispatching private Pro build for ${TAG} with R2 prefix ${r2_prefix}."
build_dispatch="$(
jq -n \
diff --git a/.github/workflows/helm-pages.yml b/.github/workflows/helm-pages.yml
index d91493c562..c410c853ff 100644
--- a/.github/workflows/helm-pages.yml
+++ b/.github/workflows/helm-pages.yml
@@ -103,8 +103,8 @@ jobs:
fi
validated_version="${VERSION}"
- echo "version=${validated_version}" >> "$GITHUB_OUTPUT"
- echo "release_tag=${release_tag}" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py version "${validated_version}"
+ python3 scripts/write_github_output.py release_tag "${release_tag}"
- name: Download immutable qualified chart
env:
diff --git a/.github/workflows/install-sh-smoke.yml b/.github/workflows/install-sh-smoke.yml
index c0c0fd7358..b4b6012a51 100644
--- a/.github/workflows/install-sh-smoke.yml
+++ b/.github/workflows/install-sh-smoke.yml
@@ -138,11 +138,11 @@ jobs:
exit 1
;;
esac
- echo "tag=$tag" >> "$GITHUB_OUTPUT"
- echo "version=$version" >> "$GITHUB_OUTPUT"
- echo "repo=$repo" >> "$GITHUB_OUTPUT"
- echo "asset_source=$asset_source" >> "$GITHUB_OUTPUT"
- echo "release_id=$release_id" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py tag "$tag"
+ python3 scripts/write_github_output.py version "$version"
+ python3 scripts/write_github_output.py repo "$repo"
+ python3 scripts/write_github_output.py asset_source "$asset_source"
+ python3 scripts/write_github_output.py release_id "$release_id"
echo "Resolved: tag=$tag version=$version repo=$repo asset_source=$asset_source release_id=${release_id:-none}"
- name: Download install.sh + sshsig + linux-amd64 tarball
diff --git a/.github/workflows/promote-floating-tags.yml b/.github/workflows/promote-floating-tags.yml
index fda9bf886d..f80a00584f 100644
--- a/.github/workflows/promote-floating-tags.yml
+++ b/.github/workflows/promote-floating-tags.yml
@@ -45,6 +45,13 @@ jobs:
packages: write
steps:
+ - name: Checkout repository
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ fetch-depth: 0
+ fetch-tags: true
+
- name: Extract tag from trigger
id: extract
env:
@@ -59,17 +66,10 @@ jobs:
exit 1
fi
- echo "tag=${TAG}" >> $GITHUB_OUTPUT
- echo "prerelease=${PRERELEASE}" >> $GITHUB_OUTPUT
+ python3 scripts/write_github_output.py tag "${TAG}"
+ python3 scripts/write_github_output.py prerelease "${PRERELEASE}"
echo "Promoting floating tags for ${TAG} (prerelease: ${PRERELEASE})"
- - name: Checkout repository
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- with:
- persist-credentials: false
- fetch-depth: 0
- fetch-tags: true
-
- name: Validate release line policy
env:
TAG: ${{ steps.extract.outputs.tag }}
diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml
index 50f7bc0e51..11c4ade217 100644
--- a/.github/workflows/publish-docker.yml
+++ b/.github/workflows/publish-docker.yml
@@ -75,8 +75,8 @@ jobs:
echo "Detected prerelease version"
fi
- echo "tag=${TAG}" >> $GITHUB_OUTPUT
- echo "version=${VERSION}" >> $GITHUB_OUTPUT
+ python3 scripts/write_github_output.py tag "${TAG}"
+ python3 scripts/write_github_output.py version "${VERSION}"
echo "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUT
echo "Publishing Docker images for ${TAG} (prerelease: ${IS_PRERELEASE})"
diff --git a/.github/workflows/qualify-secure-runtime-release.yml b/.github/workflows/qualify-secure-runtime-release.yml
index 3165f99a4e..8738362d9a 100644
--- a/.github/workflows/qualify-secure-runtime-release.yml
+++ b/.github/workflows/qualify-secure-runtime-release.yml
@@ -18,6 +18,11 @@ jobs:
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
+ - name: Checkout release qualification control
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
- name: Resolve immutable RC identity
id: release
env:
@@ -44,7 +49,7 @@ jobs:
sleep 10
done
release_id="$(jq -er '.id | select(type == "number" and . > 0)' "${release_json}")"
- echo "tag=${tag}" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py tag "${tag}"
echo "release_id=${release_id}" >> "$GITHUB_OUTPUT"
- name: Checkout exact release tag
@@ -67,7 +72,7 @@ jobs:
test "$(git branch --show-current)" = ""
test -z "$(git status --short --untracked-files=all)"
git merge-base --is-ancestor "${commit}" origin/main
- echo "commit=${commit}" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py commit "${commit}"
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
diff --git a/.github/workflows/recover-demo-server.yml b/.github/workflows/recover-demo-server.yml
index 63f0c23295..d157130715 100644
--- a/.github/workflows/recover-demo-server.yml
+++ b/.github/workflows/recover-demo-server.yml
@@ -64,7 +64,9 @@ jobs:
set -euo pipefail
TAG="${WORKFLOW_OUTPUT_1}"
PROFILE_OUTPUT="$(bash .github/scripts/resolve-demo-runtime-profile.sh "refs/tags/${TAG}")"
- printf '%s\n' "$PROFILE_OUTPUT" >> "$GITHUB_OUTPUT"
+ while IFS='=' read -r output_name output_value; do
+ python3 scripts/write_github_output.py "$output_name" "$output_value"
+ done <<< "$PROFILE_OUTPUT"
printf 'Resolved stable demo recovery profile for %s:\n%s\n' "$TAG" "$PROFILE_OUTPUT"
- name: Connect to the governed demo network
diff --git a/.github/workflows/recover-release-activation.yml b/.github/workflows/recover-release-activation.yml
index 858ae67f6d..370aa0f17c 100644
--- a/.github/workflows/recover-release-activation.yml
+++ b/.github/workflows/recover-release-activation.yml
@@ -134,12 +134,12 @@ jobs:
run_created_date=$(jq -r '.created_at | fromdateiso8601 | strftime("%Y%m%d")' "${source_run}")
r2_prefix="${TAG}-pro-${run_created_date}-${SOURCE_RELEASE_RUN_ID}"
- echo "version=${version}" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py version "${version}"
echo "source_sha=${source_sha}" >> "$GITHUB_OUTPUT"
echo "release_id=${release_id}" >> "$GITHUB_OUTPUT"
echo "is_prerelease=${is_prerelease}" >> "$GITHUB_OUTPUT"
- echo "manifest_artifact=${manifest_artifact}" >> "$GITHUB_OUTPUT"
- echo "r2_prefix=${r2_prefix}" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py manifest_artifact "${manifest_artifact}"
+ python3 scripts/write_github_output.py r2_prefix "${r2_prefix}"
echo "[OK] ${TAG} is eligible for activation-only recovery from run ${SOURCE_RELEASE_RUN_ID}."
- name: Revalidate the immutable staged candidate
diff --git a/.github/workflows/update-demo-server.yml b/.github/workflows/update-demo-server.yml
index dd7fed3192..c0075119eb 100644
--- a/.github/workflows/update-demo-server.yml
+++ b/.github/workflows/update-demo-server.yml
@@ -180,7 +180,9 @@ jobs:
TAG="${WORKFLOW_OUTPUT_1}"
TAG_REF="refs/tags/${TAG}"
PROFILE_OUTPUT="$(bash .github/scripts/resolve-demo-runtime-profile.sh "${TAG_REF}")"
- printf '%s\n' "$PROFILE_OUTPUT" >> "$GITHUB_OUTPUT"
+ while IFS='=' read -r output_name output_value; do
+ python3 scripts/write_github_output.py "$output_name" "$output_value"
+ done <<< "$PROFILE_OUTPUT"
printf 'Resolved target-compatible demo runtime profile for %s:\n%s\n' "$TAG" "$PROFILE_OUTPUT"
update-demo:
diff --git a/.github/workflows/validate-release-assets.yml b/.github/workflows/validate-release-assets.yml
index 8df1a1423d..d4930980ce 100644
--- a/.github/workflows/validate-release-assets.yml
+++ b/.github/workflows/validate-release-assets.yml
@@ -304,7 +304,7 @@ jobs:
if docker pull "$IMAGE" 2>/dev/null; then
echo "✓ Docker image available: $IMAGE"
echo "image_available=true" >> $GITHUB_OUTPUT
- echo "image=$IMAGE" >> $GITHUB_OUTPUT
+ python3 scripts/write_github_output.py image "$IMAGE"
exit 0
fi
diff --git a/scripts/check_workflow_trust.py b/scripts/check_workflow_trust.py
index 818bc840e9..a507931063 100644
--- a/scripts/check_workflow_trust.py
+++ b/scripts/check_workflow_trust.py
@@ -28,7 +28,11 @@ ENV_ENTRY_RE = re.compile(r"^\s*([A-Za-z_][A-Za-z0-9_]*)\s*:\s*(.*?)\s*$")
EXPRESSION_RE = re.compile(r"\$\{\{(.*?)\}\}")
GITHUB_COMMAND_FILE_RE = re.compile(r"\bGITHUB_(?:ENV|OUTPUT|PATH|STATE)\b")
SHELL_ASSIGNMENT_RE = re.compile(
- r"^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*="
+ r"^\s*(?:(?:export|local|readonly)\s+|declare(?:\s+-[A-Za-z]+)?\s+)?"
+ r"([A-Za-z_][A-Za-z0-9_]*)\s*="
+)
+POWERSHELL_ASSIGNMENT_RE = re.compile(
+ r"^\s*(?:\[[^\]\r\n]+\]\s*)?\$([A-Za-z_][A-Za-z0-9_]*)\s*="
)
# Workflow-call and dispatch inputs are data, not shell source. The legacy
# github.event.inputs alias is identical data, and repository_dispatch callers
@@ -250,7 +254,8 @@ def _shell_variable_reference(line: str, name: str) -> bool:
escaped = re.escape(name)
return bool(
re.search(
- rf"(?:\$\{{{escaped}(?::?[-+?=][^}}]*)?\}}|\${escaped}\b|\$env:{escaped}\b)",
+ rf"(?:\$\{{{escaped}(?=[^A-Za-z0-9_])|\${escaped}\b|"
+ rf"\$env:{escaped}\b|\$\{{env:{escaped}\}})",
line,
re.IGNORECASE,
)
@@ -277,28 +282,44 @@ def _audit_command_file_data(
for name, value in _step_env_bindings(lines, run_index).items()
if _is_untrusted_expression(value)
}
- event_payload_variables: set[str] = set()
+ unsafe_names = set(bindings)
for script_index, script_line in _run_script_lines(lines, run_index):
assignment = SHELL_ASSIGNMENT_RE.match(script_line)
- if assignment and "GITHUB_EVENT_PATH" in script_line:
- event_payload_variables.add(assignment.group(1))
+ if assignment is None:
+ assignment = POWERSHELL_ASSIGNMENT_RE.match(script_line)
+ if assignment:
+ assigned_name = assignment.group(1)
+ assignment_value = script_line[assignment.end() :]
+ if (
+ "GITHUB_EVENT_PATH" in assignment_value
+ or any(
+ _shell_variable_reference(assignment_value, name)
+ for name in unsafe_names
+ )
+ ):
+ unsafe_names.add(assigned_name)
+ else:
+ # A later literal or trusted assignment replaces the prior
+ # value. Keeping stale taint would hide real findings in noise
+ # and encourage suppressions around the policy.
+ unsafe_names.discard(assigned_name)
if not GITHUB_COMMAND_FILE_RE.search(script_line):
continue
- unsafe_names = sorted(
+ referenced_unsafe_names = sorted(
name
- for name in (*bindings, *event_payload_variables)
+ for name in unsafe_names
if _shell_variable_reference(script_line, name)
)
- if unsafe_names:
+ if referenced_unsafe_names:
findings.append(
Finding(
path,
script_index + 1,
"untrusted workflow data must be validated or encoded "
"before writing to GitHub command files "
- f"({', '.join(unsafe_names)})",
+ f"({', '.join(referenced_unsafe_names)})",
)
)
return findings
diff --git a/scripts/installtests/build_release_assets_test.go b/scripts/installtests/build_release_assets_test.go
index 5e747e22ec..7c1c17b2fb 100644
--- a/scripts/installtests/build_release_assets_test.go
+++ b/scripts/installtests/build_release_assets_test.go
@@ -973,7 +973,7 @@ func TestCreateReleaseUploadsPowerShellInstaller(t *testing.T) {
`--rawfile body "$NOTES_FILE"`,
`--input "$RELEASE_PAYLOAD"`,
`--expected-body-file "$NOTES_FILE"`,
- `historical_asset_backfill_only=${HISTORICAL_ASSET_BACKFILL_ONLY}`,
+ `write_github_output.py historical_asset_backfill_only "${HISTORICAL_ASSET_BACKFILL_ONLY}"`,
`if: ${{ always() && needs.prepare.result == 'success' && needs.build_release_candidate.result == 'success' && needs.create_release.result == 'success' && needs.prepare.outputs.historical_asset_backfill_only != 'true' }}`,
`candidate_manifest_artifact: ${{ needs.build_release_candidate.outputs.manifest_artifact_name }}`,
`if: ${{ needs.prepare.outputs.historical_asset_backfill_only == 'true' }}`,
@@ -3571,7 +3571,7 @@ func TestReleasePipelinePromotesOneImmutableCandidate(t *testing.T) {
!strings.Contains(createJob, `Resuming quarantined draft release for ${TAG}`) {
t.Fatal("release creation must explicitly support resuming a quarantined draft")
}
- if !strings.Contains(createJob, `release_activation_committed=${RELEASE_ACTIVATION_COMMITTED}`) ||
+ if !strings.Contains(createJob, `write_github_output.py release_activation_committed "${RELEASE_ACTIVATION_COMMITTED}"`) ||
!strings.Contains(createJob, `[ "$EXISTING_RELEASE_ACTIVATION_COMMITTED" != "true" ]`) ||
!strings.Contains(createJob, `[ "$ACTIVATION_COMMITTED" != "true" ]`) {
t.Fatal("release creation must refuse to retarget a draft whose irreversible activation marker exists")
@@ -3757,7 +3757,7 @@ func TestCreateReleasePublishesPrivateProRuntime(t *testing.T) {
`repos/rcourtman/pulse-enterprise/actions/workflows/build-pro-release.yml/dispatches`,
`build_run_id="$(jq -r '.workflow_run_id // empty' <<<"${build_dispatch}")"`,
`wait_for_workflow rcourtman/pulse-enterprise "${build_run_id}" "private Pro build"`,
- `echo "r2_prefix=${r2_prefix}" >> "$GITHUB_OUTPUT"`,
+ `write_github_output.py r2_prefix "${r2_prefix}"`,
} {
if !strings.Contains(stageJob, needle) {
t.Fatalf("stage_private_pro_runtime missing required contract: %s", needle)
diff --git a/scripts/tests/test_workflow_trust.py b/scripts/tests/test_workflow_trust.py
index 26bac7fa4e..e463f7f517 100644
--- a/scripts/tests/test_workflow_trust.py
+++ b/scripts/tests/test_workflow_trust.py
@@ -439,7 +439,38 @@ jobs:
4,
)
- def test_accepts_validated_command_file_values(self) -> None:
+ def test_rejects_aliased_workflow_data_in_github_command_files(self) -> None:
+ findings = self.audit(
+ """permissions: {}
+jobs:
+ unsafe:
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ steps:
+ - env:
+ RELEASE_NAME: ${{ inputs.release_name }}
+ run: |
+ alias="$RELEASE_NAME"
+ copied="prefix-${alias}"
+ printf 'release=%s\\n' "$copied" >> "$GITHUB_OUTPUT"
+ trimmed="${RELEASE_NAME#v}"
+ printf 'trimmed=%s\\n' "${trimmed}" >> "$GITHUB_OUTPUT"
+ - shell: pwsh
+ env:
+ RELEASE_NAME: ${{ inputs.release_name }}
+ run: |
+ $alias = $env:RELEASE_NAME
+ "release=$alias" >> $env:GITHUB_OUTPUT
+ [string] $braced = "${env:RELEASE_NAME}"
+ "braced=$braced" >> $env:GITHUB_OUTPUT
+"""
+ )
+ self.assertEqual(
+ sum("validated or encoded" in finding for finding in findings),
+ 4,
+ )
+
+ def test_accepts_safe_command_file_writer_for_validated_values(self) -> None:
findings = self.audit(
"""permissions: {}
jobs:
@@ -452,7 +483,7 @@ jobs:
run: |
[[ "$RELEASE_INPUT" =~ ^v[0-9]+\\.[0-9]+\\.[0-9]+$ ]]
validated_release="$RELEASE_INPUT"
- printf 'release=%s\\n' "$validated_release" >> "$GITHUB_OUTPUT"
+ python3 scripts/write_github_output.py release "$validated_release"
"""
)
self.assertEqual(findings, [])
diff --git a/scripts/tests/test_write_github_output.py b/scripts/tests/test_write_github_output.py
new file mode 100644
index 0000000000..ee99dc79a9
--- /dev/null
+++ b/scripts/tests/test_write_github_output.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+"""Tests for the injection-safe GitHub output writer."""
+
+from __future__ import annotations
+
+import importlib.util
+import sys
+import tempfile
+import unittest
+from pathlib import Path
+
+
+REPO_ROOT = Path(__file__).resolve().parents[2]
+MODULE_PATH = REPO_ROOT / "scripts" / "write_github_output.py"
+SPEC = importlib.util.spec_from_file_location("write_github_output", MODULE_PATH)
+assert SPEC and SPEC.loader
+write_github_output = importlib.util.module_from_spec(SPEC)
+sys.modules[SPEC.name] = write_github_output
+SPEC.loader.exec_module(write_github_output)
+
+
+class WriteGitHubOutputTest(unittest.TestCase):
+ def test_arbitrary_lines_remain_inside_one_collision_free_record(self) -> None:
+ tokens = iter(("collision", "safe"))
+ value = "v1\npulse_output_collision\ninjected=surprise"
+ with tempfile.TemporaryDirectory() as temporary_directory:
+ output = Path(temporary_directory) / "output"
+ write_github_output.append_output(
+ output, "release", value, lambda: next(tokens)
+ )
+ self.assertEqual(
+ output.read_text(encoding="utf-8"),
+ "release<<pulse_output_safe\n"
+ f"{value}\n"
+ "pulse_output_safe\n",
+ )
+
+ def test_rejects_names_that_can_create_another_command(self) -> None:
+ with tempfile.TemporaryDirectory() as temporary_directory:
+ with self.assertRaises(ValueError):
+ write_github_output.append_output(
+ Path(temporary_directory) / "output",
+ "release\ninjected",
+ "v1",
+ )
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/scripts/write_github_output.py b/scripts/write_github_output.py
new file mode 100644
index 0000000000..3297692d79
--- /dev/null
+++ b/scripts/write_github_output.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python3
+"""Append one value to GITHUB_OUTPUT without permitting command injection."""
+
+from __future__ import annotations
+
+import os
+import re
+import secrets
+import sys
+from collections.abc import Callable
+from pathlib import Path
+
+
+OUTPUT_NAME_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
+
+
+def append_output(
+ path: Path,
+ name: str,
+ value: str,
+ token_factory: Callable[[], str] | None = None,
+) -> None:
+ """Append *value* under *name* using a collision-free multiline record."""
+ if not OUTPUT_NAME_RE.fullmatch(name):
+ raise ValueError(f"invalid GitHub output name: {name!r}")
+ if "\x00" in value:
+ raise ValueError("GitHub output values must not contain NUL bytes")
+
+ make_token = token_factory or (lambda: secrets.token_hex(16))
+ value_lines = set(value.splitlines())
+ while True:
+ delimiter = f"pulse_output_{make_token()}"
+ if delimiter not in value_lines:
+ break
+
+ with path.open("a", encoding="utf-8", newline="\n") as output:
+ output.write(f"{name}<<{delimiter}\n")
+ output.write(value)
+ if not value.endswith("\n"):
+ output.write("\n")
+ output.write(f"{delimiter}\n")
+
+
+def main() -> int:
+ if len(sys.argv) != 3:
+ print(f"usage: {Path(sys.argv[0]).name} NAME VALUE", file=sys.stderr)
+ return 2
+ output_path = os.environ.get("GITHUB_OUTPUT")
+ if not output_path:
+ print("GITHUB_OUTPUT is required", file=sys.stderr)
+ return 2
+ try:
+ append_output(Path(output_path), sys.argv[1], sys.argv[2])
+ except (OSError, ValueError) as error:
+ print(f"could not write GitHub output: {error}", file=sys.stderr)
+ return 1
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())