Skip to content

Commit

Permalink
feat: add support for protocol (http or https) in CORS origins
Browse files Browse the repository at this point in the history
  • Loading branch information
seansica committed Dec 30, 2024
1 parent 86222fa commit e154a89
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ function validateDomains(value) {
? value

Check failure on line 101 in app/config/config.js

View workflow job for this annotation

GitHub Actions / static-checks

'?' should be placed at the end of the line
: value.split(',').map(origin => origin.trim());

Check failure on line 102 in app/config/config.js

View workflow job for this annotation

GitHub Actions / static-checks

':' should be placed at the end of the line

// Regex to validate FQDNs
const fqdnRegex = /^(?!:\/\/)([a-zA-Z0-9-_]+\.)+[a-zA-Z]{2,}$/;
// Regex to validate FQDNs with or without protocols
const originRegex = /^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/;

origins.forEach(origin => {
if (!fqdnRegex.test(origin)) {
if (!originRegex.test(origin)) {
throw new Error(`Invalid domain: ${origin}`);
}
});
Expand Down

0 comments on commit e154a89

Please sign in to comment.