Skip to content

Commit ba97360

Browse files
authored
Merge pull request #443 from ELEVATE-Project/story-1155
[story-1155] - Cross Origin Resource Sharing (CORS) Misconfiguration
2 parents 76ca18c + 57b1079 commit ba97360

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,6 @@ EVENT_ORG_LISTENER_URLS='http://interface:3567/mentoring/v1/organization/eventLi
164164
EVENT_ENABLE_ORG_EVENTS=true
165165
#Generic Email template for new users
166166
GENERIC_INVITATION_EMAIL_TEMPLATE_CODE=generic_invite
167+
168+
# Allowed host by CORS
169+
ALLOWED_HOST = "http://examplDomain.com"

src/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ app.use(bodyParser.json({ limit: '50MB' }))
6565

6666
app.use(express.static('public'))
6767

68+
// Middleware to set Access-Control-Allow-Origin header
69+
app.use((req, res, next) => {
70+
res.setHeader('Access-Control-Allow-Origin', process.env.ALLOWED_HOST)
71+
next()
72+
})
73+
6874
/* Logs request info if environment is configured to enable log */
6975
app.all('*', (req, res, next) => {
7076
logger.info('***User Service Request Log***', {

src/envVariables.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ let enviromentVariables = {
232232
optional: true,
233233
default: 'generic_invite',
234234
},
235+
ALLOWED_HOST: {
236+
message: 'Required CORS allowed host',
237+
optional: true,
238+
default: '*',
239+
},
235240
}
236241

237242
let success = true

0 commit comments

Comments
 (0)