Skip to content

Commit

Permalink
fix: Strip sensitive cookies from proxied requests (#5611)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwalters512 committed Apr 11, 2022
1 parent 179a3ea commit 741f6d4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,29 @@ module.exports.initExpress = function () {
upload.single('file')
);

/**
* Function to strip "sensitive" cookies from requests that will be proxied
* to workspace hosts.
*/
function stripSensitiveCookies(proxyReq) {
const cookies = proxyReq.getHeader('cookie');
if (!cookies) return;

const items = cookies.split(';');
const filteredItems = items.filter((item) => {
const name = item.split('=')[0].trim();
return (
name !== 'pl_authn' &&
name !== 'pl_assessmentpw' &&
// The workspace authz cookies use a prefix plus the workspace ID, so
// we need to check for that prefix instead of an exact name match.
!name.startsWith('pl_authz_workspace_')
);
});

proxyReq.setHeader('cookie', filteredItems.join(';'));
}

// proxy workspaces to remote machines
let workspaceUrlRewriteCache = new LocalCache(config.workspaceUrlRewriteCacheMaxAgeSec);
const workspaceProxyOptions = {
Expand Down Expand Up @@ -249,6 +272,12 @@ module.exports.initExpress = function () {
return 'not-matched';
}
},
onProxyReq: (proxyReq) => {
stripSensitiveCookies(proxyReq);
},
onProxyReqWs: (proxyReq) => {
stripSensitiveCookies(proxyReq);
},
onError: (err, req, res) => {
logger.error(`Error proxying workspace request: ${err}`, {
err,
Expand Down

0 comments on commit 741f6d4

Please sign in to comment.