diff --git a/.github/workflows/upstreaming-worker.lock.yml b/.github/workflows/upstreaming-worker.lock.yml index d6edac1a8db..d9c56bbc7bd 100644 --- a/.github/workflows/upstreaming-worker.lock.yml +++ b/.github/workflows/upstreaming-worker.lock.yml @@ -1,4 +1,4 @@ -# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"f59accebadca45d1eaf227c55b70d831463daaf6d3ce5e3f0780948bb30fe9dd","body_hash":"c2baea3582364d048cf2d83f3eaae073738dda88c35c483d78b99c7d2d6689b9","compiler_version":"v1.2.2","strict":true,"agent_id":"pi","agent_model":"anthropic/claude-opus-5-5","engine_versions":{"pi":"1.5.0"}} +# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"1ecac67c591c2dc4f11faa96584780eea9395b748d6db9a94ef3f7abff725ea5","body_hash":"c2baea3582364d048cf2d83f3eaae073738dda88c35c483d78b99c7d2d6689b9","compiler_version":"v1.2.2","strict":true,"agent_id":"pi","agent_model":"anthropic/claude-opus-5-5","engine_versions":{"pi":"1.5.0"}} # gh-aw-manifest: {"version":1,"secrets":["ANTHROPIC_API_KEY","COPILOT_GITHUB_TOKEN","GH_AW_DEFAULT_OTLP_ENDPOINT","GH_AW_DEFAULT_OTLP_HEADERS","GH_AW_GITHUB_MCP_SERVER_TOKEN","GH_AW_GITHUB_TOKEN","GITHUB_TOKEN","RISEPROJECT_APP_PRIVATE_KEY","RISEPROJECT_UPSTREAMING_APP_PRIVATE_KEY"],"actions":[{"repo":"actions/checkout","sha":"3d3c42e5aac5ba805825da76410c181273ba90b1","version":"v7.0.1"},{"repo":"actions/create-github-app-token","sha":"64ab729a6294000f5aa4a4bc0b73d1f32bc45510","version":"v3.3.0"},{"repo":"actions/download-artifact","sha":"9000827ccba6bdab643e8b6fd33ac0654aef8333","version":"v8.0.2"},{"repo":"actions/github-script","sha":"3a2844b7e9c422d3c10d287c895573f7108da1b3","version":"v9.0.0"},{"repo":"actions/setup-node","sha":"949feb2413d6458794dcd2491c4babbbce0c15c1","version":"v7.1.0"},{"repo":"actions/upload-artifact","sha":"043fb46d1a93c77aae656e7c1c64a875d1fc6a0a","version":"v7.0.1"},{"repo":"actions/upload-artifact","sha":"cf430e030ddbb5b0abf93d22962f4752f3646cd9","version":"v7.0.2"},{"repo":"astral-sh/setup-uv","sha":"20cfd1bf945f4377ade1205e4dbc17946fc9a30d","version":"v10.0.1"},{"repo":"github/gh-aw-actions/setup","sha":"53d0749e19424a918acd82b4d140264ce48f2f14","version":"v1.2.2"}],"containers":[{"image":"ghcr.io/github/gh-aw-firewall/agent:0.29.11","digest":"sha256:8774a73c351395b41d2ad0af4ddb4689007c67de3cd08bd9f43bb8a0e300690e","pinned_image":"ghcr.io/github/gh-aw-firewall/agent:0.29.11@sha256:8774a73c351395b41d2ad0af4ddb4689007c67de3cd08bd9f43bb8a0e300690e"},{"image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.29.11","digest":"sha256:88d2d0e315a504d93fd4fb8847fd0f6b7f4469f41a6fc6047b3dc9654c56ab2c","pinned_image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.29.11@sha256:88d2d0e315a504d93fd4fb8847fd0f6b7f4469f41a6fc6047b3dc9654c56ab2c"},{"image":"ghcr.io/github/gh-aw-firewall/squid:0.29.11","digest":"sha256:861739ecf924dd2db5e5fb652db2ad82aaafd1615623297ddabc8f41a36b2847","pinned_image":"ghcr.io/github/gh-aw-firewall/squid:0.29.11@sha256:861739ecf924dd2db5e5fb652db2ad82aaafd1615623297ddabc8f41a36b2847"},{"image":"ghcr.io/github/gh-aw-mcpg:v0.5.6","digest":"sha256:342cd624e1f179d91be2de7a146fc4f387092e62e6c8a47506d7932e113d2311","pinned_image":"ghcr.io/github/gh-aw-mcpg:v0.5.6@sha256:342cd624e1f179d91be2de7a146fc4f387092e62e6c8a47506d7932e113d2311"},{"image":"ghcr.io/github/gh-aw-node","digest":"sha256:8735428c2d4e602f90781ba0c571c400e8ff93c7ee1508a75d71f87e34e415cc","pinned_image":"ghcr.io/github/gh-aw-node@sha256:8735428c2d4e602f90781ba0c571c400e8ff93c7ee1508a75d71f87e34e415cc"},{"image":"ghcr.io/github/github-mcp-server:v2.1.0","digest":"sha256:f6056fc10bfffcc8c81a6417a2e9ca12808647e8dd6049642a4feaadee0e0f8a","pinned_image":"ghcr.io/github/github-mcp-server:v2.1.0@sha256:f6056fc10bfffcc8c81a6417a2e9ca12808647e8dd6049642a4feaadee0e0f8a"}],"mcp_servers":[{"name":"github","tools":["get_commit","get_file_contents","get_latest_release","get_me","get_pull_request","get_pull_request_comments","get_pull_request_diff","get_pull_request_files","get_pull_request_review_comments","get_pull_request_reviews","get_pull_request_status","get_release_by_tag","get_tag","issue_read","list_branches","list_commits","list_issue_types","list_issues","list_pull_requests","list_releases","list_starred_repositories","list_tags","pull_request_read","search_code","search_issues","search_pull_requests","search_repositories"]},{"name":"github-authenticated","tools":["actions_list","get_commit","get_file_contents","get_pull_request","get_pull_request_comments","get_pull_request_diff","get_pull_request_files","get_pull_request_review_comments","get_pull_request_reviews","get_pull_request_status","issue_read","list_commits","list_issues","list_pull_requests","pull_request_read","search_code","search_issues","search_pull_requests"]},{"name":"safeoutputs","tools":["noop","report_incomplete","report_missing_data","report_missing_tool","upload_artifact"]},{"name":"work-queue","tools":["work_queue_claim_finish","work_queue_dispatch_next","work_queue_explain","work_queue_read","work_queue_submit"]}],"threat_detection":{"mode":"enabled"},"admission":false,"work_queue":{"worker":true,"logical_contract":"056b332b022951fc3d1ae91c58cb202ea509dcef2a5d2c296a6cc0a9f8abc00a"},"agent_metadata":{}} # This file was automatically generated by gh-aw (v1.2.2). DO NOT EDIT. To debug this workflow, load the skill at https://github.com/github/gh-aw/blob/main/debug.md # @@ -733,6 +733,15 @@ jobs: env: GH_AW_SKILL_DIR: ".pi/skills" run: bash "${RUNNER_TEMP}/gh-aw/actions/restore_inline_skills.sh" + - uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 + with: + enable-cache: false + - env: + GH_AW_ACTIONS_DIR: ${{ runner.temp }}/gh-aw/actions + name: Guard the Actions log from untrusted workflow commands + run: | + set -euo pipefail + uv run --no-project python -m upstreaming.gh_aw_log_guard "$GH_AW_ACTIONS_DIR" - env: GH_AW_ACTIONS_DIR: ${{ runner.temp }}/gh-aw/actions name: Check out the contribution fork at the expected head (read-only) diff --git a/.github/workflows/upstreaming-worker.md b/.github/workflows/upstreaming-worker.md index fd0be19ee71..afd87d4c324 100644 --- a/.github/workflows/upstreaming-worker.md +++ b/.github/workflows/upstreaming-worker.md @@ -68,6 +68,15 @@ safe-outputs: noop: report-as-issue: false pre-agent-steps: + - uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 + with: + enable-cache: false + - name: Guard the Actions log from untrusted workflow commands + env: + GH_AW_ACTIONS_DIR: ${{ runner.temp }}/gh-aw/actions + run: | + set -euo pipefail + uv run --no-project python -m upstreaming.gh_aw_log_guard "$GH_AW_ACTIONS_DIR" - name: Check out the contribution fork at the expected head (read-only) env: GH_AW_ACTIONS_DIR: ${{ runner.temp }}/gh-aw/actions diff --git a/SESSIONLOG.md b/SESSIONLOG.md index 646b94e45d7..30b57366855 100644 --- a/SESSIONLOG.md +++ b/SESSIONLOG.md @@ -28,3 +28,4 @@ - Added trusted post-publication review acknowledgements: every addressed feedback item gets a short App-authored response, inline review threads are resolved after replying, and marker/readback checks make retries idempotent. - Added a fast ungrouped controller job that idempotently reacts `+1` to visible `/upstreaming` tracking-issue comments while leaving all parsing, authorization and command effects in serialized reconciliation. - Aligned the controller's cheap comment filter with first-nonblank-line command parsing so blank-line-prefixed commands are both acknowledged and reconciled. +- Added a hash-pinned gh-aw v1.2.2 console guard that preserves canonical agent evidence while preventing untrusted model or MCP text from being parsed as GitHub Actions workflow commands. diff --git a/upstreaming/INTEGRATION.md b/upstreaming/INTEGRATION.md index 19cdf356352..7d7e704099e 100644 --- a/upstreaming/INTEGRATION.md +++ b/upstreaming/INTEGRATION.md @@ -41,6 +41,11 @@ release-path rehearsal still need live evidence. - The dispatcher and patch worker stay sandboxed. The worker's native detector currently uses a provider-specific CLI; Pi-only detection is an unresolved compatibility limitation and is not silently worked around. +- Before worker model execution, trusted code hash-checks the pinned gh-aw + v1.2.2 process runner and patches only its console-forwarding path. Every + colon byte in untrusted child output gains a following space in the Actions + log, so model and MCP content cannot become `::workflow-command::` syntax, + including across output chunks. Canonical artifact evidence stays unchanged. ## Deployed and observed remotely diff --git a/upstreaming/gh_aw_log_guard.py b/upstreaming/gh_aw_log_guard.py new file mode 100644 index 00000000000..b205f606918 --- /dev/null +++ b/upstreaming/gh_aw_log_guard.py @@ -0,0 +1,83 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +"""Hash-pinned guard against GitHub workflow commands in agent output. + +The canonical agent stream remains unchanged in its artifact. Only the child +process bytes forwarded to the Actions console are made command-safe. +""" + +from __future__ import annotations + +import argparse +import hashlib +from pathlib import Path + +SOURCE_SHA256 = "28c69eb1c56469eac2e1182fea6cde195ee95c698b8412b5ed85c821e331b8f6" +PATCHED_SHA256 = "74bb397cd5e0502d4a83c6c9e9a9d838d52d588b4402807f1f24b97178f21326" + +IMPORT_NEEDLE = '''const { StringDecoder } = require("string_decoder"); +''' +IMPORT_REPLACEMENT = '''const { StringDecoder } = require("string_decoder"); + +// Agent and tool output is untrusted. GitHub Actions interprets any line that +// begins with two colons as a runner command. Insert a space after every colon +// byte only in the console copy. Operating on bytes keeps this safe across +// output chunks and preserves the canonical stream collected for artifacts. +function workflowCommandSafe(data) { + let colonCount = 0; + for (const byte of data) if (byte === 0x3a) colonCount += 1; + if (colonCount === 0) return data; + const safe = Buffer.allocUnsafe(data.length + colonCount); + let target = 0; + for (const byte of data) { + safe[target++] = byte; + if (byte === 0x3a) safe[target++] = 0x20; + } + return safe; +} +''' +WRITE_REPLACEMENTS = { + "process.stdout.write(data)": "process.stdout.write(workflowCommandSafe(data))", + "process.stderr.write(data)": "process.stderr.write(workflowCommandSafe(data))", +} + + +def digest(data: bytes) -> str: + return hashlib.sha256(data).hexdigest() + + +def patch_bytes(source: bytes, *, verify_source: bool = True) -> bytes: + if verify_source and digest(source) != SOURCE_SHA256: + raise RuntimeError("gh-aw process_runner.cjs does not match pinned v1.2.2 input") + text = source.decode() + if text.count(IMPORT_NEEDLE) != 1: + raise RuntimeError("gh-aw process_runner import anchor is missing or ambiguous") + text = text.replace(IMPORT_NEEDLE, IMPORT_REPLACEMENT) + for old, new in WRITE_REPLACEMENTS.items(): + if text.count(old) != 1: + raise RuntimeError(f"gh-aw process_runner write anchor is missing or ambiguous: {old}") + text = text.replace(old, new) + return text.encode() + + +def apply(actions_dir: Path) -> None: + path = actions_dir / "process_runner.cjs" + source = path.read_bytes() + if PATCHED_SHA256 != "TO_BE_FILLED" and digest(source) == PATCHED_SHA256: + return + patched = patch_bytes(source) + if PATCHED_SHA256 == "TO_BE_FILLED" or digest(patched) != PATCHED_SHA256: + raise RuntimeError("gh-aw process_runner.cjs patched output hash mismatch") + path.write_bytes(patched) + + +def main(argv=None) -> int: + parser = argparse.ArgumentParser() + parser.add_argument("actions_dir", type=Path) + args = parser.parse_args(argv) + apply(args.actions_dir) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/upstreaming/tests/test_gh_aw_log_guard.py b/upstreaming/tests/test_gh_aw_log_guard.py new file mode 100644 index 00000000000..9415d56ec03 --- /dev/null +++ b/upstreaming/tests/test_gh_aw_log_guard.py @@ -0,0 +1,44 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT + +import subprocess +import unittest + +from upstreaming import gh_aw_log_guard + + +SYNTHETIC = b'''const { StringDecoder } = require("string_decoder"); +function forwardOut(data) { return process.stdout.write(data); } +function forwardErr(data) { return process.stderr.write(data); } +''' + + +class TestGhAwLogGuard(unittest.TestCase): + def test_patch_rejects_unpinned_runtime(self): + with self.assertRaisesRegex(RuntimeError, "does not match pinned"): + gh_aw_log_guard.patch_bytes(SYNTHETIC) + + def test_console_copy_cannot_form_workflow_command_across_chunks(self): + patched = gh_aw_log_guard.patch_bytes(SYNTHETIC, verify_source=False).decode() + script = patched + ''' +process.stdout.write(workflowCommandSafe(Buffer.from(":"))); +process.stdout.write(workflowCommandSafe(Buffer.from(":add-matcher::bad"))); +process.stdout.write("\\n"); +process.stdout.write(workflowCommandSafe(Buffer.from("::error::bad"))); +''' + result = subprocess.run(["node", "-e", script], check=True, capture_output=True) + output = result.stdout.decode() + self.assertNotIn("::", output) + self.assertIn(": : add-matcher: : bad", output) + self.assertIn(": : error: : bad", output) + + def test_patch_changes_only_forwarded_console_bytes(self): + patched = gh_aw_log_guard.patch_bytes(SYNTHETIC, verify_source=False).decode() + self.assertIn("process.stdout.write(workflowCommandSafe(data))", patched) + self.assertIn("process.stderr.write(workflowCommandSafe(data))", patched) + self.assertNotIn("stdout = collect(stdout, workflowCommandSafe", patched) + self.assertNotIn("stderr = collect(stderr, workflowCommandSafe", patched) + + +if __name__ == "__main__": + unittest.main()