Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: security problem #1799

Merged
merged 1 commit into from
Mar 29, 2024
Merged
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
25 changes: 13 additions & 12 deletions src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function wrapper(context) {

resolve(next());
},
req
req,
);
});
}
Expand All @@ -99,7 +99,8 @@ function wrapper(context) {
const extra = {};
const filename = getFilenameFromUrl(
context,
/** @type {string} */ (req.url)
/** @type {string} */ (req.url),
extra,
);

if (!filename) {
Expand Down Expand Up @@ -149,7 +150,7 @@ function wrapper(context) {
*/
(header) => {
setHeaderForResponse(res, header.key, header.value);
}
},
);
}

Expand All @@ -165,7 +166,7 @@ function wrapper(context) {
setHeaderForResponse(
res,
"Content-Type",
context.options.mimeTypeDefault
context.options.mimeTypeDefault,
);
}
}
Expand Down Expand Up @@ -213,7 +214,7 @@ function wrapper(context) {
setHeaderForResponse(
res,
"Content-Range",
getValueContentRangeHeader("bytes", size)
getValueContentRangeHeader("bytes", size),
);
setHeaderForResponse(res, "Content-Type", "text/html; charset=utf-8");

Expand All @@ -224,7 +225,7 @@ function wrapper(context) {
setHeaderForResponse(
res,
"Content-Length",
Buffer.byteLength(document)
Buffer.byteLength(document),
);

if (context.options.modifyResponseData) {
Expand All @@ -233,7 +234,7 @@ function wrapper(context) {
req,
res,
document,
byteLength
byteLength,
));
}

Expand All @@ -242,11 +243,11 @@ function wrapper(context) {
return;
} else if (parsedRanges === -2) {
context.logger.error(
"A malformed 'Range' header was provided. A regular response will be sent for this request."
"A malformed 'Range' header was provided. A regular response will be sent for this request.",
);
} else if (parsedRanges.length > 1) {
context.logger.error(
"A 'Range' header with multiple ranges was provided. Multiple ranges are not supported, so a regular response will be sent for this request."
"A 'Range' header with multiple ranges was provided. Multiple ranges are not supported, so a regular response will be sent for this request.",
);
}

Expand All @@ -259,8 +260,8 @@ function wrapper(context) {
getValueContentRangeHeader(
"bytes",
size,
/** @type {import("range-parser").Ranges} */ (parsedRanges)[0]
)
/** @type {import("range-parser").Ranges} */ (parsedRanges)[0],
),
);

[{ start, end }] = parsedRanges;
Expand Down Expand Up @@ -304,7 +305,7 @@ function wrapper(context) {
req,
res,
bufferOrStream,
byteLength
byteLength,
));
}

Expand Down
Loading