Merge pull request #388 from PR0M3TH3AN/jules-fix-governance-injection-12456679039303197057

🔒 Fix Argument Injection in rollbackPrompt
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-02-25 10:42:16 -05:00
commit cdda3ae0f4
5 files changed
+26 -26

No files matched your search

-1
View File
@@ -61,7 +61,6 @@ function filterActiveLocks(locks) {
return locks.filter((lock) => !lock.expiresAt || lock.expiresAt > now);
}
/**
* Queries relays for active lock events matching the criteria.
* Uses a tiered approach: tries primary relays first, then falls back to others if needed.
+2 -7
View File
@@ -6,8 +6,9 @@ import {
getRelayFallbacks,
getMinActiveRelayPool,
} from './torch-config.mjs';
import { mergeRelayList, secureRandom, withTimeout } from './lock-utils.mjs';
import { defaultHealthManager, buildRelayHealthConfig } from './relay-health-manager.mjs';
import { mergeRelayList, withTimeout, relayListLabel } from './lock-utils.mjs';
import { relayListLabel } from './utils.mjs';
const PUBLISH_ERROR_CODES = {
TIMEOUT: 'publish_timeout',
@@ -100,12 +101,6 @@ function isTransientPublishCategory(category) {
].includes(category);
}
const MAX_RANDOM = 281474976710655; // 2**48 - 1
export function secureRandom() {
return randomInt(0, MAX_RANDOM) / MAX_RANDOM;
}
function calculateBackoffDelayMs(attemptNumber, baseMs, capMs, randomFn = secureRandom) {
const maxDelay = Math.min(capMs, baseMs * (2 ** Math.max(0, attemptNumber - 1)));
return Math.floor(randomFn() * maxDelay);
+20 -17
View File
@@ -3,7 +3,7 @@ import path from 'node:path';
import { randomInt } from 'node:crypto';
import { todayDateStr, getIsoWeekStr } from './utils.mjs';
export { relayListLabel } from './utils.mjs';
export { relayListLabel, mergeRelayList } from './utils.mjs';
/**
* Scans the local log directory to identify agents that have already completed their task
@@ -14,7 +14,25 @@ export { relayListLabel } from './utils.mjs';
* @param {Object} deps - Dependency injection for testing
* @returns {Promise<Set<string>>} - Set of agent names that have completed their task
*/
export async function getCompletedAgents(cadence, logDir, deps = {}) {
/**
* Promisified timeout wrapper.
*
* @param {Promise} promise - The promise to wrap.
* @param {number} timeoutMs - Timeout in milliseconds.
* @param {string} timeoutMessage - Error message on timeout.
* @returns {Promise} - The result of the promise or a timeout error.
*/
export function withTimeout(promise, timeoutMs, timeoutMessage) {
let timeoutHandle;
const timeoutPromise = new Promise((_, reject) => {
timeoutHandle = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
});
return Promise.race([promise, timeoutPromise]).finally(() => {
if (timeoutHandle) clearTimeout(timeoutHandle);
});
}
export async function getCompletedAgents(cadence, logDir, deps) {
const { readdir = fs.readdir, getDateStr = todayDateStr, getIsoWeek = getIsoWeekStr } = deps;
const completed = new Set();
const targetDir = path.join(logDir, cadence);
@@ -51,21 +69,6 @@ export async function getCompletedAgents(cadence, logDir, deps = {}) {
return completed;
}
export function withTimeout(promise, timeoutMs, timeoutMessage = 'Operation timed out') {
let timer;
const timeoutPromise = new Promise((_, reject) => {
timer = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
});
return Promise.race([
promise.finally(() => clearTimeout(timer)),
timeoutPromise,
]);
}
export function mergeRelayList(primaryRelays, fallbackRelays) {
return [...new Set([...primaryRelays, ...fallbackRelays])];
}
const MAX_RANDOM = 281474976710655; // 2**48 - 1
export function secureRandom() {
+1 -1
View File
@@ -4,7 +4,7 @@ import WebSocket from 'ws';
import { finalizeEvent, generateSecretKey, getPublicKey } from 'nostr-tools/pure';
import { getNamespace, getRelays } from './torch-config.mjs';
import { MS_PER_SECOND } from './constants.mjs';
import { withTimeout } from './lock-utils.mjs';
import { withTimeout } from './utils.mjs';
const PROBE_KIND = 27235;
+3
View File
@@ -355,6 +355,9 @@ export async function rollbackPrompt(target, hashOrStrategy = 'latest') {
// Fallback to Git
try {
const commit = hashOrStrategy === 'latest' ? 'HEAD' : hashOrStrategy;
if (commit.startsWith('-')) {
throw new Error(`Invalid commit/strategy: ${commit} (cannot start with '-')`);
}
execFileSync('git', ['checkout', commit, '--', target]);
return { success: true, source: 'git', restored: commit };
} catch (e) {