DEV Community

Origami
Origami

Posted on • Edited on

5

webpack-dev-serverでdisableHostCheckを使うのはもうやめろ

TL;DR

DO NOT USE disableHostCheck. because its potentially vulnerable.
USE host: "0.0.0.0 and useLocalIp. its safe, for now.

ハローこんにちは。disableHostCheck: trueを使うのをやめろ。

disableHostCheckを使うのにはだいたい理由があって、たとえばiPhoneからPC上のlocalhostで動いているサイトを見たいという理由でdisableHostChecktrueにしたりしてアクセスしたりします。

Alt Text

[マシン名].local:[ポート番号]でアクセスするのはiPhoneを使った開発ではよく見る光景ですね。このときdisableHostCheckはだいたいInvalid Host headerを回避するために使います。

しかし、disableHostCheckを有効にするとDNS rebinding attack脆弱性を抱えてしまいますし、実際に webpack-dev-serverのdocumentationでも非推奨 の方法となっています。
代わりに今の所、useLocalIP: trueを使えば解決することができます。

config.devServer = {
    host: "0.0.0.0",
    useLocalIp: true,
}

Enter fullscreen mode Exit fullscreen mode

host: "0.0.0.0"はないと動かないので注意。
この方法を使えばdisableHostCheckを回避できます。自分のローカルIPアドレスを使ってやればアクセスできるので、ネットワークによってURLは変更されますが。

Alt Text

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay