Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/upstreaming-worker.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .github/workflows/upstreaming-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions SESSIONLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 5 additions & 0 deletions upstreaming/INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
83 changes: 83 additions & 0 deletions upstreaming/gh_aw_log_guard.py
Original file line number Diff line number Diff line change
@@ -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())
44 changes: 44 additions & 0 deletions upstreaming/tests/test_gh_aw_log_guard.py
Original file line number Diff line number Diff line change
@@ -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()