Skip to content

Backport security fix from v5.2.1 to version-4 (non-Chromium browser dev-server vulnerability) #5534

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

Open
wants to merge 2 commits into
base: version-4
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"use strict";

function isTrustedClient(req) {
// Only allow injection if client explicitly identifies itself
return req.headers["webpack-dev-server-client"] === "true";
}

const os = require("os");
const path = require("path");
const url = require("url");
Expand Down Expand Up @@ -2103,6 +2108,13 @@ class Server {
/** @type {import("webpack-dev-middleware").API<Request, Response>}*/
(middleware).waitUntilValid((stats) => {
res.setHeader("Content-Type", "text/html");

if (!isTrustedClient(req)) {
res.statusCode = 403;
res.end("Access denied: Missing required dev server client header.");
return;
}

res.write(
'<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body>'
);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-dev-server",
"version": "4.15.2",
"name": "webpack-dev-server-wajih",
"version": "4.6.0-patched",
"description": "Serves a webpack app. Updates the browser on changes.",
"bin": "bin/webpack-dev-server.js",
"main": "lib/Server.js",
Expand Down