webpack-dev-server icon indicating copy to clipboard operation
webpack-dev-server copied to clipboard

"Invalid Host/Origin Header" warning

Open ravshansbox opened this issue 7 years ago • 59 comments

PLEASE READ

We are working on this problem. It is regression problem after fixing security error. Security issues are always high priority and we would not want to revert it, but it is require some changes in https://github.com/sockjs/sockjs-node/pull/247, we have workaround for this problem https://github.com/webpack/webpack-dev-server/pull/1608, but need some feedback. Feel free to feedback.

Fast workaround (put it in your devServer property in config):

disableHostCheck: true




We apologize for the situation. Thanks for helping us do webpack better. :star: :star: :star:


  • Operating System: macos 10.14.2
  • Node Version: 11.5.0
  • NPM Version: 6.4.1
  • webpack Version: 4.28.1
  • webpack-dev-server Version: 3.1.11
  • [x] This is a bug

Code

  // webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  entry: [
    './src/main.css',
    './src/main.js'
  ],
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'index.js'
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/main.html'
    }),
    new MiniCssExtractPlugin({
      filename: 'index.css'
    })
  ],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader'
        ]
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: 'babel-loader'
      }
    ]
  },
  stats: {
    children: false,
    modules: false
  },
  devServer: {
    proxy: {
      '/api': 'http://localhost:3000'
    },
    stats: {
      children: false,
      modules: false
    }
  }
};

Expected Behavior

No warnings

Actual Behavior

Getting "Invalid Host/Origin Header" warning in browser console

For Bugs; How can we reproduce the behavior?

install [email protected] and run (v3.1.10 working as expected).

image

ravshansbox avatar Dec 21 '18 18:12 ravshansbox

@ravshansbox it is security fix, looks you origin than you use in config, you can use disableHostCheck: true in you case, anyway can you create minimum reproducible test repo?

alexander-akait avatar Dec 21 '18 18:12 alexander-akait

@evilebottnawi yes, sure, here you are: https://github.com/ravshansbox/webpack-dev-server-sample

ravshansbox avatar Dec 21 '18 18:12 ravshansbox

with disableHostCheck: true there is no warning.

ravshansbox avatar Dec 21 '18 18:12 ravshansbox

@ravshansbox thanks, i will look in near future, but if original is not same it is normal have this error

alexander-akait avatar Dec 21 '18 18:12 alexander-akait

I have the same issue. Problem here is that browser does not send origin header at all. Here my debug of connection object

SockJSConnection { _session: Session { session_id: undefined, heartbeat_delay: 25000, disconnect_delay: 5000, prefix: '/sockjs-node', send_buffer: [], is_closing: false, readyState: 1, timeout_cb: [Function], to_tref: Timeout { _called: false, _idleTimeout: 25000, _idlePrev: [Object], _idleNext: [Object], _idleStart: 1740, _onTimeout: [Function], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(asyncId)]: 6686, [Symbol(triggerAsyncId)]: 6679 }, connection: [Circular], emit_open: null, recv: WebSocketReceiver { ws: [Object], connection: [Object], heartbeat_cb: [Function], thingy: [Object], thingy_end_cb: [Function], session: [Circular] } }, id: 'da07ccdf-4d74-4fed-a48b-6d76247e97af', headers: { host: 'localhost:8080', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36', 'accept-language': 'pl,en;q=0.9,en-US;q=0.8,fr;q=0.7' }, prefix: '/sockjs-node', remoteAddress: '127.0.0.1', remotePort: 37412, address: { address: '127.0.0.1', family: 'IPv4', port: 8080 }, url: '/sockjs-node/599/ngnhxajl/websocket', pathname: '/sockjs-node/599/ngnhxajl/websocket', protocol: 'websocket' } `

pkk82 avatar Dec 21 '18 20:12 pkk82

I am seeing this issue as well with 3.1.11. Rolling back to 3.1.10 fixes it.

bwigs avatar Dec 21 '18 21:12 bwigs

Also, got this issue after upgrading to 3.1.11

rpang77 avatar Dec 21 '18 23:12 rpang77

I also am getting this error in Firefox 64.0 with version 3.1.11. Reverting to 3.1.10 fixes it.

lambcode avatar Dec 22 '18 06:12 lambcode

I confirm, the same problem. Manjaro linux (4.19.8-2-MANJARO) Firefox DE 65.0b2 Node LTS (10.14.2)

Akiyamka avatar Dec 22 '18 08:12 Akiyamka

Same problem here

juank11memphis avatar Dec 22 '18 13:12 juank11memphis

Please read https://github.com/webpack/webpack-dev-server/issues/1604#issuecomment-449465737

alexander-akait avatar Dec 22 '18 13:12 alexander-akait

Please try https://github.com/webpack/webpack-dev-server/releases/tag/v3.1.12

alexander-akait avatar Dec 22 '18 15:12 alexander-akait

I can confirm that the issue still exists.

ravshansbox avatar Dec 22 '18 15:12 ravshansbox

I can also confirm that the issue still exists

davidpelayo avatar Dec 22 '18 15:12 davidpelayo

Please don't spam Same problem here or issue still exists, better create minimum reproducible test repo, it is allow to fix all edge cases, thanks!

alexander-akait avatar Dec 22 '18 16:12 alexander-akait

I checked request sent to dev-server via Chrome in localhost, request doesn't have Origin header.

{ host: 'localhost:8080',
  'user-agent':
   'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
  'accept-language': 'ja-JP,ja;q=0.9,en-US;q=0.8,en;q=0.7' }

checkHeader will return false when value is empty, so this issue still exists, I think.

https://github.com/webpack/webpack-dev-server/blob/e614308fed6eafc2fccce37837fd16c406f54116/lib/Server.js#L644-L646

3846masa avatar Dec 22 '18 16:12 3846masa

Sockjs will remove Origin header. Ref. https://github.com/sockjs/sockjs-node/pull/247

3846masa avatar Dec 22 '18 16:12 3846masa

In my opinion, it is better to revert #1603 until sockjs/sockjs-node#247 is merged.

3846masa avatar Dec 22 '18 16:12 3846masa

@3846masa let's wait some time and revert it, maybe we can implement workaround on our side, need investigate, feel free to do it, thanks

alexander-akait avatar Dec 22 '18 16:12 alexander-akait

I tried to add workaround (#1608). It works and resolves this issue in my environment. Please check it.

3846masa avatar Dec 22 '18 18:12 3846masa