Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Prod QA] Fix CSP for statement frames on Desktop #9804

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ _.assign(console, log.functions);
// until it detects that it has been upgraded to the correct version.

const EXPECTED_UPDATE_VERSION_FLAG = '--expected-update-version';
const APP_DOMAIN = __DEV__ ? `http://localhost:${port}` : 'app://-';

let expectedUpdateVersion;
for (let i = 0; i < process.argv.length; i++) {
Expand Down Expand Up @@ -159,18 +160,19 @@ const mainWindow = (() => {
details.requestHeaders.referer = CONFIG.EXPENSIFY.URL_EXPENSIFY_CASH;
callback({requestHeaders: details.requestHeaders});
});

// Modify access-control-allow-origin header for the response
webRequest.onHeadersReceived(validDestinationFilters, (details, callback) => {
details.responseHeaders['access-control-allow-origin'] = ['app://-'];
callback({responseHeaders: details.responseHeaders});
});
} else {
webRequest.onHeadersReceived(validDestinationFilters, (details, callback) => {
details.responseHeaders['access-control-allow-origin'] = [`http://localhost:${process.env.PORT}`];
callback({responseHeaders: details.responseHeaders});
});
}

// Modify access-control-allow-origin header and CSP for the response
webRequest.onHeadersReceived(validDestinationFilters, (details, callback) => {
details.responseHeaders['access-control-allow-origin'] = [APP_DOMAIN];
if (details.responseHeaders['content-security-policy']) {
details.responseHeaders['content-security-policy'] = _.map(
details.responseHeaders['content-security-policy'],
value => (value.startsWith('frame-ancestors') ? `${value} ${APP_DOMAIN}` : value),
);
}
callback({responseHeaders: details.responseHeaders});
});
/* eslint-enable */

// Prod and staging overwrite the app name in the electron-builder config, so only update it here for dev
Expand Down