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

Parameterize and Update CORS and CSP #244

Merged
merged 6 commits into from
May 24, 2024
29 changes: 22 additions & 7 deletions frontend/scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import cors from 'cors';
import helmet from 'helmet';
import express from 'express';
import path from 'path';
import { ALLOW_ORIGIN, ALLOW_METHODS } from './constants.js';

export const app = express();

Expand All @@ -17,25 +16,41 @@ app.use((req, res, next) => {
next();
});

app.use(cors({ origin: ALLOW_ORIGIN, methods: ALLOW_METHODS }));
app.use(
cors({
origin: [
/^https:\/\/(.*\.)?crossfeed\.cyber\.dhs\.gov$/,
/^https:\/\/(.*\.)?readysetcyber\.cyber\.dhs\.gov$/
],
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']
})
);

app.use(
helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: [
"'self'",
'https://cognito-idp.us-east-1.amazonaws.com',
'https://api.staging-cd.crossfeed.cyber.dhs.gov'
'https://cognito-idp.*.amazonaws.com',
'https://*.crossfeed.cyber.dhs.gov',
'https://*.readysetcyber.cyber.dhs.gov'
],
frameSrc: ["'self'", 'https://www.dhs.gov/ntas/'],
imgSrc: [
"'self'",
'https://*.crossfeed.cyber.dhs.gov',
'https://*.readysetcyber.cyber.dhs.gov',
'https://www.dhs.gov'
],
objectSrc: ["'none'"],
scriptSrc: [
"'self'",
'https://api.staging-cd.crossfeed.cyber.dhs.gov'
// Add any other allowed script sources here
'https://*.crossfeed.cyber.dhs.gov',
'https://*.readysetcyber.cyber.dhs.gov',
'https://www.dhs.gov'
],
frameAncestors: ["'none'"]
// Add other directives as needed
}
},
hsts: {
Expand Down
3 changes: 0 additions & 3 deletions frontend/scripts/constants.js

This file was deleted.

12 changes: 9 additions & 3 deletions frontend/scripts/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import path from 'path';
import rateLimit from 'express-rate-limit';
import cors from 'cors';
import helmet from 'helmet';
import { ALLOW_ORIGIN, ALLOW_METHODS } from './constants.js';

export const app = express();

Expand All @@ -17,8 +16,15 @@ app.use(

app.use(express.static(path.join(__dirname, '../docs/build')));

app.use(cors({ origin: ALLOW_ORIGIN, methods: ALLOW_METHODS }));

app.use(
cors({
origin: [
/^https:\/\/(.*\.)?crossfeed\.cyber\.dhs\.gov$/,
/^https:\/\/(.*\.)?readysetcyber\.cyber\.dhs\.gov$/
],
methods: 'GET'
})
);
app.use(
helmet({
contentSecurityPolicy: {
Expand Down
Loading