Skip to content

Commit e8e0a06

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(atlassian): sanitize malformed discovery responses
1 parent 807e2f4 commit e8e0a06

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

apps/sim/lib/atlassian/discovery.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ describe('resolveAtlassianCloudId', () => {
136136
expect(error.message).not.toContain('provider-body-secret-marker')
137137
})
138138

139+
it('omits malformed successful response bodies from selector discovery errors', async () => {
140+
fetchMock.mockResolvedValue({
141+
ok: true,
142+
status: 200,
143+
headers: new Headers(),
144+
json: vi
145+
.fn()
146+
.mockRejectedValue(new SyntaxError('invalid provider-body-secret-marker JSON payload')),
147+
})
148+
149+
const error = await resolveAtlassianCloudId(
150+
options({
151+
retryOptions: { ...FAST, omitResponseBodyFromErrors: true },
152+
})
153+
).catch((caught) => caught as Error)
154+
155+
expect(error.message).toBe('Failed to fetch Jira accessible resources: invalid JSON response')
156+
expect(error.message).not.toContain('provider-body-secret-marker')
157+
expect(fetchMock).toHaveBeenCalledTimes(1)
158+
})
159+
139160
it('does not pin a failure in the cache', async () => {
140161
fetchMock.mockResolvedValueOnce(failure(403, { message: 'nope' }))
141162
await expect(resolveAtlassianCloudId(options({ retryOptions: FAST }))).rejects.toThrow()

apps/sim/lib/atlassian/discovery.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,14 @@ export function fetchAtlassianDiscoveryJson<T>(
172172
throw error
173173
}
174174

175-
return (await response.json()) as T
175+
try {
176+
return (await response.json()) as T
177+
} catch (error) {
178+
if (omitResponseBodyFromErrors) {
179+
throw new Error(`${failureLabel}: invalid JSON response`)
180+
}
181+
throw error
182+
}
176183
},
177184
{ ...ATLASSIAN_DISCOVERY_RETRY_OPTIONS, ...effectiveRetryOptions }
178185
)

0 commit comments

Comments
 (0)