1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

[PM-21644] Cannot retrieve attachment from bw serve (#14806)

* Modified saveAttachmenttofIle to implement callback attachment content decryption

* renamed parameter
This commit is contained in:
SmithThe4th
2025-05-22 09:15:30 -04:00
committed by GitHub
parent 068c63e891
commit 46a0b709fe
3 changed files with 28 additions and 16 deletions

View File

@@ -2,8 +2,6 @@
// @ts-strict-ignore
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service";
import { EncArrayBuffer } from "@bitwarden/common/platform/models/domain/enc-array-buffer";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { Response } from "../models/response";
import { FileResponse } from "../models/response/file.response";
@@ -25,15 +23,15 @@ export abstract class DownloadCommand {
/**
* Fetches an attachment via the url, decrypts it's content and saves it to a file
* @param url - url used to retrieve the attachment
* @param key - SymmetricCryptoKey to decrypt the file contents
* @param fileName - filename used when written to disk
* @param decrypt - Function used to decrypt the response
* @param output - If output is empty or `--raw` was passed to the initial command the content is output onto stdout
* @returns Promise<FileResponse>
*/
protected async saveAttachmentToFile(
url: string,
key: SymmetricCryptoKey,
fileName: string,
decrypt: (resp: globalThis.Response) => Promise<Uint8Array>,
output?: string,
) {
const response = await this.apiService.nativeFetch(
@@ -46,8 +44,7 @@ export abstract class DownloadCommand {
}
try {
const encBuf = await EncArrayBuffer.fromResponse(response);
const decBuf = await this.encryptService.decryptFileData(encBuf, key);
const decBuf = await decrypt(response);
if (process.env.BW_SERVE === "true") {
const res = new FileResponse(Buffer.from(decBuf), fileName);
return Response.success(res);