From 4c85e3d2ac2893bcbec1b344e417af6bfd3047af Mon Sep 17 00:00:00 2001 From: Alessandro Benoit Date: Fri, 21 Jul 2023 15:36:05 +0200 Subject: [PATCH] fix(download): properly parse content-disposition filename (#6159) --- packages/insomnia/package-lock.json | 38 +++++++++++++++++++ packages/insomnia/package.json | 2 + .../src/ui/components/request-url-bar.tsx | 3 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/insomnia/package-lock.json b/packages/insomnia/package-lock.json index 9ab00c0c0..7c40b0393 100644 --- a/packages/insomnia/package-lock.json +++ b/packages/insomnia/package-lock.json @@ -28,6 +28,7 @@ "change-case": "^4.1.2", "clone": "^2.1.0", "color": "^3.1.2", + "content-disposition": "^0.5.4", "dompurify": "^3.0.5", "electron-context-menu": "^3.6.1", "electron-log": "^4.4.8", @@ -73,6 +74,7 @@ "@types/clone": "^2.1.0", "@types/codemirror": "^5.60.2", "@types/color": "^3.0.1", + "@types/content-disposition": "^0.5.5", "@types/deep-equal": "^1.0.1", "@types/dompurify": "^2.3.3", "@types/hawk": "9.0.2", @@ -5952,6 +5954,12 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/content-disposition": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/@types/content-disposition/-/content-disposition-0.5.5.tgz", + "integrity": "sha512-v6LCdKfK6BwcqMo+wYW05rLS12S0ZO0Fl4w1h4aaZMD7bqT3gVUns6FvLJKGZHQmYn3SX55JWGpziwJRwVgutA==", + "dev": true + }, "node_modules/@types/crypto-js": { "version": "4.0.1", "dev": true, @@ -8315,6 +8323,36 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz", "integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==" }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-disposition/node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/convert-source-map": { "version": "1.7.0", "license": "MIT", diff --git a/packages/insomnia/package.json b/packages/insomnia/package.json index 134055837..9cc4860a5 100644 --- a/packages/insomnia/package.json +++ b/packages/insomnia/package.json @@ -59,6 +59,7 @@ "change-case": "^4.1.2", "clone": "^2.1.0", "color": "^3.1.2", + "content-disposition": "^0.5.4", "dompurify": "^3.0.5", "electron-context-menu": "^3.6.1", "electron-log": "^4.4.8", @@ -122,6 +123,7 @@ "@types/clone": "^2.1.0", "@types/codemirror": "^5.60.2", "@types/color": "^3.0.1", + "@types/content-disposition": "^0.5.5", "@types/deep-equal": "^1.0.1", "@types/dompurify": "^2.3.3", "@types/hawk": "9.0.2", diff --git a/packages/insomnia/src/ui/components/request-url-bar.tsx b/packages/insomnia/src/ui/components/request-url-bar.tsx index b8f12f54d..8a31333a7 100644 --- a/packages/insomnia/src/ui/components/request-url-bar.tsx +++ b/packages/insomnia/src/ui/components/request-url-bar.tsx @@ -1,3 +1,4 @@ +import * as contentDisposition from 'content-disposition'; import type { SaveDialogOptions } from 'electron'; import fs from 'fs'; import { extension as mimeExtension } from 'mime-types'; @@ -125,7 +126,7 @@ export const RequestUrlBar = forwardRef(({ const responsePatch = await network.send(request._id, activeEnvironment?._id); const headers = responsePatch.headers || []; const header = getContentDispositionHeader(headers); - const nameFromHeader = header ? header.value : null; + const nameFromHeader = header ? contentDisposition.parse(header.value).parameters.filename : null; if ( responsePatch.bodyPath &&