Skip to content
Open
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
18 changes: 15 additions & 3 deletions .github/actions/diff/publish-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ git fetch origin rugsnare/status --depth=1 2>/dev/null || true
if git show origin/rugsnare/status:status.json >/dev/null 2>&1; then
EXISTING_RAW=$(git show origin/rugsnare/status:status.json)
EXISTING=$(printf '%s' "$EXISTING_RAW" | node -e "
const d = JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8'));
const d = JSON.parse(require('fs').readFileSync(0, 'utf8'));
// compare everything except timestamp/runId (they change every run)
delete d.timestamp; delete d.runId;
console.log(JSON.stringify(d));
" 2>/dev/null || echo "{}")
NEW=$(printf '%s' "$STATUS_JSON" | node -e "
const d = JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8'));
const d = JSON.parse(require('fs').readFileSync(0, 'utf8'));
delete d.timestamp; delete d.runId;
console.log(JSON.stringify(d));
")
Expand All @@ -67,13 +67,25 @@ if git show origin/rugsnare/status:status.json >/dev/null 2>&1; then
fi
# ISO-8601 UTC timestamps compare correctly as strings
EXISTING_TS=$(printf '%s' "$EXISTING_RAW" | node -e "
const d = JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8'));
const d = JSON.parse(require('fs').readFileSync(0, 'utf8'));
console.log(typeof d.timestamp === 'string' ? d.timestamp : '');
" 2>/dev/null || echo "")
if [ -n "$EXISTING_TS" ] && [ "$EXISTING_TS" \> "$TIMESTAMP" ]; then
echo "::notice::Status branch already has a newer run ($EXISTING_TS > $TIMESTAMP) - skipping stale re-run"
exit 0
fi
# T-039 F-4: runId is the authoritative recency signal - a re-run of an OLD
# run finishes later (newer timestamp) but must never overwrite the status
# of a newer run. Existing runId >= ours -> skip.
EXISTING_RUN=$(printf '%s' "$EXISTING_RAW" | node -e "
const d = JSON.parse(require('fs').readFileSync(0, 'utf8'));
console.log(Number.isFinite(Number(d.runId)) ? String(Number(d.runId)) : '');
" 2>/dev/null || echo "")
OUR_RUN=$(node -e "console.log(Number.isFinite(Number(process.env.GITHUB_RUN_ID)) ? String(Number(process.env.GITHUB_RUN_ID)) : '')" 2>/dev/null || echo "")
if [ -n "$EXISTING_RUN" ] && [ -n "$OUR_RUN" ] && [ "$EXISTING_RUN" -ge "$OUR_RUN" ]; then
echo "::notice::Status branch already has run $EXISTING_RUN >= our $OUR_RUN - skipping stale re-run"
exit 0
fi
fi

# Write to a temp branch: single-file orphan commit, force-pushed
Expand Down
4 changes: 2 additions & 2 deletions product/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"supply-chain", "ci"
],
"scripts": {
"test": "node --test test/security-canary.test.js test/security-runtime.test.js test/runtime-mode.test.js test/runtime-integrity.test.js test/core.test.js test/proxy.test.js test/proxy-http.test.js test/rpc-edge.test.js test/rpc-http.test.js test/auth.test.js test/results.test.js test/keccak.test.js test/onchain.test.js test/shadow.test.js test/advisory.test.js test/prompts.test.js test/policies.test.js test/canary.test.js test/canary-replay.test.js test/canary-http.test.js test/receipts.test.js test/mcp-server.test.js test/chameleon.test.js test/v041.test.js test/wrap.test.js test/v05.test.js test/adhoc-url.test.js test/doctor.test.js test/events.test.js test/config.test.js test/scan-e2e.test.js test/approve.test.js test/sarif.test.js test/audit.test.js test/vault.test.js test/budgets.test.js test/pins-sig.test.js test/review28.test.js test/undeclared.test.js test/skills-pin.test.js test/version.test.js test/history.test.js test/history-web.test.js test/gradation.test.js test/skills-advisory.test.js test/pinv11.test.js",
"prepack": "node --test test/security-canary.test.js test/security-runtime.test.js test/runtime-mode.test.js test/runtime-integrity.test.js test/core.test.js test/proxy.test.js test/proxy-http.test.js test/rpc-edge.test.js test/rpc-http.test.js test/auth.test.js test/results.test.js test/keccak.test.js test/onchain.test.js test/shadow.test.js test/advisory.test.js test/prompts.test.js test/policies.test.js test/canary.test.js test/canary-replay.test.js test/canary-http.test.js test/receipts.test.js test/mcp-server.test.js test/chameleon.test.js test/v041.test.js test/wrap.test.js test/v05.test.js test/adhoc-url.test.js test/doctor.test.js test/events.test.js test/config.test.js test/scan-e2e.test.js test/approve.test.js test/sarif.test.js test/audit.test.js test/vault.test.js test/budgets.test.js test/pins-sig.test.js test/review28.test.js test/undeclared.test.js test/skills-pin.test.js test/version.test.js test/history.test.js test/history-web.test.js test/gradation.test.js test/skills-advisory.test.js test/pinv11.test.js"
"test": "node --test test/security-canary.test.js test/security-runtime.test.js test/runtime-mode.test.js test/runtime-integrity.test.js test/core.test.js test/proxy.test.js test/proxy-http.test.js test/rpc-edge.test.js test/rpc-http.test.js test/auth.test.js test/results.test.js test/keccak.test.js test/onchain.test.js test/shadow.test.js test/advisory.test.js test/prompts.test.js test/policies.test.js test/canary.test.js test/canary-replay.test.js test/canary-http.test.js test/receipts.test.js test/mcp-server.test.js test/chameleon.test.js test/v041.test.js test/wrap.test.js test/v05.test.js test/adhoc-url.test.js test/doctor.test.js test/events.test.js test/config.test.js test/scan-e2e.test.js test/approve.test.js test/sarif.test.js test/audit.test.js test/vault.test.js test/budgets.test.js test/pins-sig.test.js test/review28.test.js test/undeclared.test.js test/publish-status.test.js test/skills-pin.test.js test/version.test.js test/history.test.js test/history-web.test.js test/gradation.test.js test/skills-advisory.test.js test/pinv11.test.js",
"prepack": "node --test test/security-canary.test.js test/security-runtime.test.js test/runtime-mode.test.js test/runtime-integrity.test.js test/core.test.js test/proxy.test.js test/proxy-http.test.js test/rpc-edge.test.js test/rpc-http.test.js test/auth.test.js test/results.test.js test/keccak.test.js test/onchain.test.js test/shadow.test.js test/advisory.test.js test/prompts.test.js test/policies.test.js test/canary.test.js test/canary-replay.test.js test/canary-http.test.js test/receipts.test.js test/mcp-server.test.js test/chameleon.test.js test/v041.test.js test/wrap.test.js test/v05.test.js test/adhoc-url.test.js test/doctor.test.js test/events.test.js test/config.test.js test/scan-e2e.test.js test/approve.test.js test/sarif.test.js test/audit.test.js test/vault.test.js test/budgets.test.js test/pins-sig.test.js test/review28.test.js test/undeclared.test.js test/publish-status.test.js test/skills-pin.test.js test/version.test.js test/history.test.js test/history-web.test.js test/gradation.test.js test/skills-advisory.test.js test/pinv11.test.js"
}
}

11 changes: 8 additions & 3 deletions product/src/pins.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ export function detectShadows(pins) {

export function pinTool(serverPin, tool, hash, { approved = true, reason = 'scan' } = {}) {
const now = new Date().toISOString();
const existing = serverPin.tools[tool.name];
// own-property only (T-039 F-2): proto names must not surface phantom entries
const existing = Object.hasOwn(serverPin.tools, tool.name) ? serverPin.tools[tool.name] : undefined;
// PIN-SPEC v1.1 byte-stability: a ROUTINE SCAN that sees the SAME contract
// of an ALREADY-APPROVED tool must not touch the entry - pinnedAt churn
// would change pins.json bytes on every re-scan and break third-party
Expand Down Expand Up @@ -303,7 +304,9 @@ export function pinTool(serverPin, tool, hash, { approved = true, reason = 'scan
pinnedAt: now,
approved,
};
return serverPin.tools[tool.name];
// own-property lookups only (T-039 F-2): 'constructor'/'toString' names
// must never resolve through Object.prototype as phantom pins
return Object.hasOwn(serverPin.tools, tool.name) ? serverPin.tools[tool.name] : undefined;
}

/**
Expand Down Expand Up @@ -778,7 +781,9 @@ export function detectPaywallIntroduction(oldDescription, newDescription) {
export function compareTools(serverPin, liveTools, toolHashFn) {
const result = [];
for (const tool of liveTools) {
const pin = serverPin.tools[tool.name];
// own-property only (T-039 F-2): 'constructor' et al. must compare as
// absent (NEW), never as a phantom inherited pin
const pin = Object.hasOwn(serverPin.tools, tool.name) ? serverPin.tools[tool.name] : undefined;
const hash = toolHashFn(tool);
if (!pin) result.push({ tool: tool.name, status: 'NEW', hash, description: tool.description ?? '' });
else if (pin.hash !== hash) {
Expand Down
39 changes: 33 additions & 6 deletions product/src/proxy-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ export function createHttpProxy({ name, targetUrl, authConfig = {}, mode = 'obse
* Create the local HTTP server that the MCP client connects to.
*/
const server = http.createServer((clientReq, clientRes) => {
// CSRF guard (T-039 F-3): a browser page must not be able to drive the
// local proxy. Same-origin loopback only; non-browser clients send no
// Origin header at all and are unaffected.
const origin = clientReq.headers.origin;
if (origin) {
const localPort = clientReq.socket.localPort;
const allowed = new Set([`http://localhost:${localPort}`, `http://127.0.0.1:${localPort}`]);
if (!allowed.has(origin)) {
logEvent({ kind: 'cross-origin-reject', server: name, origin: String(origin).slice(0, 100) }, cwd);
clientRes.writeHead(403, { 'content-type': 'application/json' });
clientRes.end(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32000, message: '[RUGSNARE] Cross-origin requests are not permitted.' } }));
return;
}
}
if (clientReq.method === 'GET') {
// Health check / SSE endpoint - just 200
clientRes.writeHead(200, { 'content-type': 'text/event-stream' });
Expand All @@ -173,16 +187,28 @@ export function createHttpProxy({ name, targetUrl, authConfig = {}, mode = 'obse
try {
const msg = JSON.parse(body);

// JSON-RPC batch (T-039 F-1): the per-message gates never see inside
// an array - reject outright in enforce, forward with a log in observe.
if (Array.isArray(msg)) {
if (mode === 'enforce') {
logEvent({ kind: 'batch-reject', server: name, entries: msg.length }, cwd);
clientRes.writeHead(200, { 'content-type': 'application/json' });
clientRes.end(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32600, message: '[RUGSNARE] JSON-RPC batch requests are not supported in enforce mode.' } }));
return;
}
logEvent({ kind: 'batch-forward', server: name, entries: msg.length }, cwd);
}

// Call policies + loop detector - same enforcement as the stdio proxy.
// A blocked call is answered directly to the client; the remote never sees it.
if (msg.method === 'tools/call' && msg.params) {
// Fail-closed for unknown-in-session names (REVIEW T-031 / T-034):
// before the first tools/list there is no allowed-cache, so in
// enforce a call to a name not in the pin is unknown - block it.
// Fail-closed for unknown-in-session names (REVIEW T-031 / T-034);
// T-039 F-2: own-property lookups only - proto names must not
// resolve through Object.prototype.
if (mode === 'enforce' && (
quarantinedTools.has(msg.params.name)
|| serverPin.tools[msg.params.name]?.approved === false
|| (!hasSeenToolsList && serverPin.tools[msg.params.name] === undefined)
|| (Object.hasOwn(serverPin.tools, msg.params.name) && serverPin.tools[msg.params.name].approved === false)
|| (!hasSeenToolsList && !Object.hasOwn(serverPin.tools, msg.params.name))
)) {
logEvent({ kind: 'quarantine-call-block', server: name, tool: msg.params.name, ...(hasSeenToolsList ? {} : { note: 'call before first tools/list; name not in pin (fail-closed)' }) }, cwd);
clientRes.writeHead(200, { 'content-type': 'application/json' });
Expand All @@ -206,7 +232,8 @@ export function createHttpProxy({ name, targetUrl, authConfig = {}, mode = 'obse
}
}

const toolPin = serverPin.tools[msg.params.name];
// own-property only (T-039 F-2): proto names must not resolve
const toolPin = Object.hasOwn(serverPin.tools, msg.params.name) ? serverPin.tools[msg.params.name] : undefined;
const policyResult = evaluateCall(
{ toolName: msg.params.name, arguments: msg.params.arguments, description: toolPin?.description ?? '' },
activePolicies
Expand Down
22 changes: 19 additions & 3 deletions product/src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,30 @@ export function createProxy({ name, server, streams, mode = 'observe', config, c
return;
}
try {
// JSON-RPC batch (array of messages) is an enforcement blind spot
// (T-039 F-1): the per-message gates below never see inside it, so an
// unapproved tool could ride a batch. Reject batches outright in
// enforce; forward (with a log line) in observe.
if (Array.isArray(msg)) {
if (mode === 'enforce') {
writeOut(JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32600, message: '[RUGSNARE] JSON-RPC batch requests are not supported in enforce mode.' } }));
logEvent({ kind: 'batch-reject', server: name, entries: msg.length }, cwd);
return;
}
logEvent({ kind: 'batch-forward', server: name, entries: msg.length }, cwd);
}
if (msg.method === 'tools/call' && msg.params) {
// Fail-closed for unknown-in-session names (REVIEW T-031 / T-034):
// before the first tools/list there is no allowed-cache, so in enforce
// a call to a name that is not even in the pin is unknown - block it.
// Pinned (approved) tools still pass; after the first list the normal
// quarantine/undeclared logic takes over.
// T-039 F-2: own-property lookups only - 'constructor'/'toString'/
// '__proto__' must not resolve through Object.prototype.
if (mode === 'enforce' && (
quarantinedTools.has(msg.params.name)
|| serverPin.tools[msg.params.name]?.approved === false
|| (!hasSeenToolsList && serverPin.tools[msg.params.name] === undefined)
|| (Object.hasOwn(serverPin.tools, msg.params.name) && serverPin.tools[msg.params.name].approved === false)
|| (!hasSeenToolsList && !Object.hasOwn(serverPin.tools, msg.params.name))
)) {
writeOut(JSON.stringify({ jsonrpc: '2.0', id: msg.id, error: { code: -32603, message: '[RUGSNARE] Tool is quarantined or has not been approved.' } }));
logEvent({ kind: 'quarantine-call-block', server: name, tool: msg.params.name, ...(hasSeenToolsList ? {} : { note: 'call before first tools/list; name not in pin (fail-closed)' }) }, cwd);
Expand Down Expand Up @@ -164,7 +178,9 @@ export function createProxy({ name, server, streams, mode = 'observe', config, c
}

// Policy evaluation: check arguments against rules
const toolPin = serverPin.tools[msg.params.name];
// (own-property lookup only - a proto name must not resolve to
// Object.prototype members as a phantom "pin")
const toolPin = Object.hasOwn(serverPin.tools, msg.params.name) ? serverPin.tools[msg.params.name] : undefined;
const policyResult = evaluateCall(
{ toolName: msg.params.name, arguments: msg.params.arguments, description: toolPin?.description ?? '' },
activePolicies
Expand Down
4 changes: 3 additions & 1 deletion product/src/skills-pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ export function pinAllSkills(pins, cwd = process.cwd(), home = os.homedir(), { p
let pinnedCount = 0;
for (const skill of skills) {
const key = `${skill.app}/${skill.scope}/${skill.relative}`;
const existing = pins.skills[key];
// own-property only (T-039 F-2 discipline): never resolve through
// Object.prototype even for adversarial key shapes
const existing = Object.hasOwn(pins.skills, key) ? pins.skills[key] : undefined;
const entry = pinSkillFile(skill, cwd);
// §7 byte-stability: a scan that sees the SAME content must not touch
// the entry - pinnedAt churn changes pins.json bytes on every re-scan
Expand Down
78 changes: 78 additions & 0 deletions product/test/publish-status.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';

// T-039 F-4: the runId guard in publish-status.sh. A re-run of an OLD CI run
// finishes with a NEWER wall-clock timestamp than the status already on the
// branch - the timestamp guard alone would let it overwrite a newer run's
// verdict. runId is the authoritative recency signal: existing >= ours -> skip.
//
// The simulation builds a local bare "origin" with a rugsnare/status branch
// (runId 200, verdict drift), then runs the real script as runId 100 - the
// skip path exits 0 BEFORE any push, so no network is touched.

const HERE = path.dirname(fileURLToPath(import.meta.url));
const SCRIPT = path.join(HERE, '..', '..', '.github', 'actions', 'diff', 'publish-status.sh');

function git(cwd, args) {
return execFileSync('git', ['-c', 'user.email=t@t', '-c', 'user.name=t', '-c', 'commit.gpgsign=false', ...args], { cwd, encoding: 'utf8', windowsHide: true });
}

function runScript(args, env, cwd) {
try {
const out = execFileSync('bash', [SCRIPT, ...args], { cwd, encoding: 'utf8', timeout: 60000, env: { ...process.env, ...env }, windowsHide: true });
return { code: 0, out };
} catch (e) {
return { code: e.status ?? 1, out: (e.stdout || '') + (e.stderr || '') };
}
}

test('T-039 F-4: stale re-run (older runId) never overwrites a newer status', () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'rugsnare-pubstatus-'));
try {
const bare = path.join(root, 'remote.git');
const work = path.join(root, 'work');
git(root, ['init', '--bare', bare]);
git(root, ['clone', bare, work]);

// seed a commit on the default branch
fs.writeFileSync(path.join(work, 'seed.txt'), 'seed');
git(work, ['add', '.']);
git(work, ['commit', '-m', 'seed']);
const mainBranch = git(work, ['rev-parse', '--abbrev-ref', 'HEAD']).trim();

// create rugsnare/status holding runId 200 (drift) with an OLD timestamp
git(work, ['checkout', '--orphan', 'rugsnare/status']);
git(work, ['rm', '-rf', '--quiet', '.']);
fs.writeFileSync(path.join(work, 'status.json'), JSON.stringify({
verdict: 'drift', findings: 3, config: '.mcp.json', timestamp: '2026-11-01T00:00:00Z',
runId: '200', repo: 'x/y', branch: mainBranch, summary: 'DRIFT DETECTED: 3 finding(s)',
}));
git(work, ['add', 'status.json']);
git(work, ['commit', '-m', 'status seed']);
git(work, ['push', 'origin', 'rugsnare/status']);
git(work, ['checkout', mainBranch]);

// act: the script runs as re-run of runId 100 (older), fresh timestamp,
// different verdict (clean) so the unchanged-dedup cannot fire first
const older = runScript(['clean', '0', '.mcp.json'], { GITHUB_RUN_ID: '100', GITHUB_REPOSITORY: 'x/y', GITHUB_REF_NAME: mainBranch }, work);
assert.equal(older.code, 0, `script must exit 0 on the skip path\n${older.out}`);
assert.match(older.out, /run 200 >= our 100/, 'runId guard fires for the stale re-run');

// the status branch is untouched
const still = JSON.parse(git(work, ['show', 'origin/rugsnare/status:status.json']));
assert.equal(still.runId, '200', 'status branch still holds run 200');
assert.equal(still.verdict, 'drift', 'drift verdict NOT overwritten by the stale clean re-run');

// same-run re-execution is also a skip (>=, not >)
const same = runScript(['clean', '0', '.mcp.json'], { GITHUB_RUN_ID: '200', GITHUB_REPOSITORY: 'x/y', GITHUB_REF_NAME: mainBranch }, work);
assert.equal(same.code, 0);
assert.match(same.out, /run 200 >= our 200/, 'same runId skipped too');
} finally {
try { fs.rmSync(root, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 }); } catch { /* Windows */ }
}
});
Loading
Loading