Skip to content

Commit

Permalink
fix: Stops auth dialog popping up on Chrome (#379)
Browse files Browse the repository at this point in the history
* If a 401 http error is returned by jolokia/cluster then Chrome displays
  an authentication dialog, which is not required and disrupts the app. To
  stop the dialog appearing, the www-authentication header needs to be
  dropped from the http response.

* webpack.config.dev.js
 * In dev mode, adding the onProxyRes property to the proxy-middleware
   allows the www-authenticate header to be removed.

* nginx.js
 * In production mode, the response is already passed through the response
   function so detecting the status is 401, the www-authenticate header can
   be removed.
  • Loading branch information
phantomjinx authored and tadayosi committed Mar 18, 2024
1 parent 95c2d5b commit 257b29c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docker/nginx.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ function proxyJolokiaAgent(req) {
for (var header in res.headersOut) {
req.headersOut[header] = res.headersOut[header];
}

if (res.status === 401) {
/*
* If an unauthorized response is received from the jolokia agent
* then want to avoid browsers like Chrome displaying a popup authentication
* dialog (initiated by the 401 status & the 'www-authenticate' header) by
* dropping the 'www-authenticate' header
*/
delete req.headersOut['www-authenticate'];
}

req.return(res.status, res.responseBody);
}

Expand Down
11 changes: 11 additions & 0 deletions packages/online-shell/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ module.exports = () => {
pathRewrite: { '^/master': '' },
secure: false,
ws: true,
onProxyRes: (proxyRes, req, res) => {
if (proxyRes.statusCode === 401) {
/*
* When both the 401 status code and the www-authenticate error are encountered
* Chrome (un)helpfully displays a pop-up login dialog. We want to disable that
* since it interferes with the probing of the jolokia connections
*/
console.log('Unauthorized Error detected: removing www-authenticate header')
delete proxyRes.headers['www-authenticate']
}
},
},
],

Expand Down

0 comments on commit 257b29c

Please sign in to comment.