Skip to content

Commit 0ed75d8

Browse files
authored
fix: add timeout to TLSNotary verifier subprocess (R-008)
Closes #23
1 parent 19d2958 commit 0ed75d8

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/infrastructure/verification/tlsn-validation.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export function isTlsnVerifierAvailable(): boolean {
8383
/** Default max attestation age: 5 minutes. */
8484
const DEFAULT_MAX_AGE_SECONDS = 300;
8585

86+
/** Timeout for the TLSNotary verifier subprocess (seconds). */
87+
const VERIFIER_TIMEOUT_SECONDS = 60;
88+
8689
function extractHostname(url: string): string | null {
8790
try {
8891
return new URL(url).hostname;
@@ -284,7 +287,24 @@ async function runVerifierBinary(
284287
stdout: "pipe",
285288
stderr: "pipe",
286289
});
287-
await proc.exited;
290+
291+
const timeoutMs = VERIFIER_TIMEOUT_SECONDS * 1000;
292+
let timer: ReturnType<typeof setTimeout>;
293+
const timedOut = await Promise.race([
294+
proc.exited.then(() => false),
295+
new Promise<boolean>((resolve) => {
296+
timer = setTimeout(() => resolve(true), timeoutMs);
297+
}),
298+
]);
299+
clearTimeout(timer!);
300+
301+
if (timedOut) {
302+
proc.kill();
303+
return {
304+
signatureValid: false,
305+
error: `verifier timed out after ${VERIFIER_TIMEOUT_SECONDS}s`,
306+
};
307+
}
288308

289309
if (proc.exitCode !== 0) {
290310
const stderr = await new Response(proc.stderr).text();

0 commit comments

Comments
 (0)