Enhance encryption security with additional safeguards.

This commit is contained in:
glay 2024-12-09 00:03:10 +08:00
parent 93337b2b92
commit a0886875e1

View File

@ -51,11 +51,6 @@ async function getBedrockHeaders(
shouldStream: boolean,
): Promise<Record<string, string>> {
const accessStore = useAccessStore.getState();
// Validate credentials
if (!accessStore.awsAccessKey || !accessStore.awsSecretKey || !accessStore.awsRegion) {
throw new Error("Missing required AWS credentials");
}
const bedrockHeaders = isApp
? await sign({
method: "POST",
@ -71,24 +66,19 @@ async function getBedrockHeaders(
: getHeaders();
if (!isApp) {
const { awsRegion, awsAccessKey, awsSecretKey, encryptionKey } = accessStore;
if (!encryptionKey) {
throw new Error("Missing encryption key");
}
const { awsRegion, awsAccessKey, awsSecretKey, encryptionKey } =
accessStore;
const bedrockHeadersConfig = {
XModelID: modelId,
XEncryptionKey: encryptionKey,
ShouldStream: String(shouldStream),
Authorization: await createAuthHeader({
region: awsRegion,
accessKey: awsAccessKey,
secretKey: awsSecretKey,
Authorization: await createAuthHeader(
awsRegion,
awsAccessKey,
awsSecretKey,
encryptionKey,
}).catch(error => {
console.error("[Bedrock] Failed to create auth header:", error);
throw new Error("Failed to create authorization header");
}),
),
};
Object.assign(bedrockHeaders, bedrockHeadersConfig);