Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/providers/bedrock/getBatchOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const getModelProvider = (modelId: string) => {
else if (modelId.includes('anthropic')) provider = 'anthropic';
else if (modelId.includes('ai21')) provider = 'ai21';
else if (modelId.includes('cohere')) provider = 'cohere';
else if (modelId.includes('amazon')) provider = 'titan';
else throw new Error('Invalid model slug');
return provider;
};
Expand Down Expand Up @@ -74,6 +75,24 @@ export const BedrockGetBatchOutputRequestHandler = async ({
headers: retrieveBatchesHeaders,
});

if (!retrieveBatchesResponse.ok) {
const error = await retrieveBatchesResponse.text();
const _error = {
message: error,
param: null,
type: null,
};
Comment on lines +79 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Security/Data Exposure

Issue: Error response includes raw error text which may expose internal details
Fix: Sanitize error message or use a generic message for production
Impact: Prevents leaking internal system details to clients

Suggested change
const error = await retrieveBatchesResponse.text();
const _error = {
message: error,
param: null,
type: null,
};
const error = await retrieveBatchesResponse.text();
const _error = {
message: 'Batch retrieval failed',
param: null,
type: null,
};

return new Response(
JSON.stringify({ error: _error, provider: BEDROCK }),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please follow the exisitng format for provider errors
Bedrock error: {errorMessage}
you can use the generateErrorResponse() utility present in /providers/utils

{
status: retrieveBatchesResponse.status,
headers: {
'Content-Type': 'application/json',
},
}
);
}

const batchDetails: BedrockGetBatchResponse =
await retrieveBatchesResponse.json();
const outputFileId = batchDetails.outputDataConfig.s3OutputDataConfig.s3Uri;
Expand Down