Skip to content

Commit f394703

Browse files
joanagmaiaclaude
andcommitted
fix: validate runDuration timestamps and truncate attached binary error fields (IN-1170)
Addresses PR review: guard computeRunDuration against missing or unparseable timestamps so NaN/negative durations don't reach the DB, and attach truncated stdout/stderr on rejected binary errors so Temporal payloads stay within serialization limits. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
1 parent b41cb74 commit f394703

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

  • services/apps/security_best_practices_worker/src/activities

services/apps/security_best_practices_worker/src/activities/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ export async function saveOSPSBaselineInsightsToDB(
150150
)
151151
}
152152
for (const assessment of evaluation['assessment-logs']) {
153-
const runDuration = assessment.end
154-
? `${new Date(assessment.end).getTime() - new Date(assessment.start).getTime()}ms`
155-
: ''
153+
const runDuration = computeRunDuration(assessment.start, assessment.end)
156154
await addControlEvaluationAssessment(qx, {
157155
applicability: assessment.applicability,
158156
description: assessment.description,
@@ -193,6 +191,14 @@ export async function saveOSPSBaselineInsightsToRedis(
193191
await redisCache.set(key, JSON.stringify(insights), 60 * 60 * 24) // 1 day
194192
}
195193

194+
function computeRunDuration(start: string | undefined, end: string | undefined): string {
195+
if (!start || !end) return ''
196+
const startMs = new Date(start).getTime()
197+
const endMs = new Date(end).getTime()
198+
if (isNaN(startMs) || isNaN(endMs) || endMs < startMs) return ''
199+
return `${endMs - startMs}ms`
200+
}
201+
196202
async function cleanupFiles(repoName: string): Promise<void> {
197203
// Delete the file
198204
try {
@@ -247,11 +253,13 @@ async function runBinary(
247253
resolve({ stdout, stderr })
248254
} else {
249255
const truncated = (s: string) => (s.length > 500 ? s.slice(0, 500) + '…' : s)
256+
const truncStdout = truncated(stdout)
257+
const truncStderr = truncated(stderr)
250258
const err = Object.assign(
251259
new Error(
252-
`Binary exited with code ${code}\nStderr:\n${truncated(stderr)}\nStdout:\n${truncated(stdout)}`,
260+
`Binary exited with code ${code}\nStderr:\n${truncStderr}\nStdout:\n${truncStdout}`,
253261
),
254-
{ stdout, stderr },
262+
{ stdout: truncStdout, stderr: truncStderr },
255263
)
256264
reject(err)
257265
}

0 commit comments

Comments
 (0)