forked from directus/directus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
match url whitelist to domain (directus#5694)
* match url whitelist to domain * Improve url-domain check * Update lockfile Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
- Loading branch information
1 parent
7ecbe49
commit c1b30a6
Showing
3 changed files
with
33 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { toArray } from './to-array'; | ||
import logger from '../logger'; | ||
|
||
/** | ||
* Check if url matches allow list either exactly or by domain+path | ||
*/ | ||
export default function isUrlAllowed(url: string, allowList: string | string[]): boolean { | ||
console.log(url, allowList); | ||
|
||
const urlAllowList = toArray(allowList); | ||
|
||
if (urlAllowList.includes(url)) return true; | ||
|
||
const parsedWhitelist = urlAllowList.map((allowedURL) => { | ||
try { | ||
const { hostname, pathname } = new URL(allowedURL); | ||
return hostname + pathname; | ||
} catch { | ||
logger.warn(`Invalid URL used "${url}"`); | ||
} | ||
}); | ||
|
||
try { | ||
const { hostname, pathname } = new URL(url); | ||
return parsedWhitelist.includes(hostname + pathname); | ||
} catch { | ||
return false; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.