Skip to content
Open
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
9 changes: 7 additions & 2 deletions packages/server/src/utils/XSS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ export function getCorsOptions(): any {
const corsOptions = {
origin: function (origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) {
const allowedOrigins = getAllowedCorsOrigins()
if (!origin || allowedOrigins == '*' || allowedOrigins.indexOf(origin) !== -1) {
if (!origin || allowedOrigins == '*') {
callback(null, true)
} else {
callback(null, false)
const allowedOriginsList = allowedOrigins.split(',').map((o) => o.trim().toLowerCase())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be pushed up for better readability and then the if condition can be rewritten asL

if (!origin || allowedOrigins == '*' || allowedOriginsList.includes(origin.toLowerCase())) {
     callback(null, true)
} else {
    callback(null, false)
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allowedOriginsList.includes

I don't want to split "allowedOrigins" if it is just '*'. If it is not * then only it splits and compares with origin.

if (allowedOriginsList.includes(origin.toLowerCase())) {
callback(null, true)
} else {
callback(null, false)
}
}
}
}
Expand Down