Skip to content

Commit ec4b90b

Browse files
committed
fix(uptimerobot): reject empty/non-object PSP responses
A successful PSP create/update must return the PspDto object; an empty or non-object body now returns a controlled 502 instead of mapping a phantom status page (id: 0, empty name, null images) back to the workflow.
1 parent 4301512 commit ec4b90b

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

apps/sim/app/api/tools/uptimerobot/server-utils.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,30 @@ export async function forwardPspRequest(options: {
118118
)
119119
}
120120

121-
let data: Record<string, unknown> = {}
122-
if (text) {
123-
try {
124-
const parsed = JSON.parse(text)
125-
if (parsed && typeof parsed === 'object') data = parsed as Record<string, unknown>
126-
} catch {
127-
logger.error(`[${requestId}] UptimeRobot returned a non-JSON PSP response`, { body: text })
128-
return NextResponse.json(
129-
{ success: false, error: 'UptimeRobot returned an unexpected response' },
130-
{ status: 502 }
131-
)
121+
// A successful PSP create/update must return the PspDto object. An empty or
122+
// non-object body is unexpected — reject it rather than mapping a phantom PSP
123+
// (id: 0, empty name, null images) back to the workflow.
124+
if (!text) {
125+
logger.error(`[${requestId}] UptimeRobot returned an empty PSP response`)
126+
return NextResponse.json(
127+
{ success: false, error: 'UptimeRobot returned an unexpected response' },
128+
{ status: 502 }
129+
)
130+
}
131+
132+
let data: Record<string, unknown>
133+
try {
134+
const parsed = JSON.parse(text)
135+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
136+
throw new Error('Expected a PSP object response')
132137
}
138+
data = parsed as Record<string, unknown>
139+
} catch {
140+
logger.error(`[${requestId}] UptimeRobot returned an unexpected PSP response`, { body: text })
141+
return NextResponse.json(
142+
{ success: false, error: 'UptimeRobot returned an unexpected response' },
143+
{ status: 502 }
144+
)
133145
}
134146
return NextResponse.json({ success: true, output: { psp: mapPsp(data) } })
135147
}

0 commit comments

Comments
 (0)