Skip to content

Commit

Permalink
fix: [breaking] send configured config URL as origin if not custom
Browse files Browse the repository at this point in the history
This is a breaking change if your install uses multiple URLs to access. You will need to update the Access-Control-Allow-Origin header in ACP > Advanced > Headers to supply all URLs you use to access your site
  • Loading branch information
julianlam committed Oct 20, 2020
1 parent 7a01949 commit 205a103
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/middleware/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const os = require('os');
const winston = require('winston');
const nconf = require('nconf');
const _ = require('lodash');

const meta = require('../meta');
Expand Down Expand Up @@ -34,6 +35,7 @@ module.exports = function (middleware) {

if (origins.includes(req.get('origin'))) {
headers['Access-Control-Allow-Origin'] = encodeURI(req.get('origin'));
headers.Vary = headers.Vary ? `${headers.Vary}, Origin` : 'Origin';
}
}

Expand All @@ -52,10 +54,15 @@ module.exports = function (middleware) {
originsRegex.forEach(function (regex) {
if (regex && regex.test(req.get('origin'))) {
headers['Access-Control-Allow-Origin'] = encodeURI(req.get('origin'));
headers.Vary = headers.Vary ? `${headers.Vary}, Origin` : 'Origin';
}
});
}

if (!headers.hasOwnProperty('Access-Control-Allow-Origin')) {
headers['Access-Control-Allow-Origin'] = nconf.get('url');
}

if (meta.config['access-control-allow-credentials']) {
headers['Access-Control-Allow-Credentials'] = meta.config['access-control-allow-credentials'];
}
Expand Down

0 comments on commit 205a103

Please sign in to comment.