-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: normalize trailing slash bridge_url param will now behave properly with or without trailing slash * feat: validate bridge_url performs validation of bridge_url in idkit-core * allow localhost bridge_url with staging app for dev work * Update packages/core/src/lib/validation.ts Co-authored-by: pdtfh <[email protected]> * fix: leading dot for domain check --------- Co-authored-by: pdtfh <[email protected]>
- Loading branch information
Showing
2 changed files
with
58 additions
and
2 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,46 @@ | ||
export type ValidationResponse = { valid: true } | { valid: false; errors: string[] } | ||
|
||
export function validate_bridge_url(bridge_url: string, is_staging?: boolean): ValidationResponse { | ||
try { | ||
new URL(bridge_url) | ||
} catch (e) { | ||
return { valid: false, errors: ['Failed to parse Bridge URL.'] } | ||
} | ||
|
||
const test_url = new URL(bridge_url) | ||
const errors: string[] = [] | ||
|
||
if (is_staging && ['localhost', '127.0.0.1'].includes(test_url.hostname)) { | ||
console.log('Using staging app_id with localhost bridge_url. Skipping validation.') | ||
return { valid: true } | ||
} | ||
|
||
if (test_url.protocol !== 'https:') { | ||
errors.push('Bridge URL must use HTTPS.') | ||
} | ||
if (test_url.port) { | ||
errors.push('Bridge URL must use the default port (443).') | ||
} | ||
if (test_url.pathname !== '/') { | ||
errors.push('Bridge URL must not have a path.') | ||
} | ||
if (test_url.search) { | ||
errors.push('Bridge URL must not have query parameters.') | ||
} | ||
if (test_url.hash) { | ||
errors.push('Bridge URL must not have a fragment.') | ||
} | ||
|
||
// remove once restriction lifted in world app | ||
if (!test_url.hostname.endsWith('.worldcoin.org') && !test_url.hostname.endsWith('.toolsforhumanity.com')) { | ||
console.warn( | ||
"Bridge URL should be a subdomain of worldcoin.org or toolsforhumanity.com. The user's identity wallet may refuse to connect. This is a temporary measure and may be removed in the future." | ||
) | ||
} | ||
|
||
if (errors.length) { | ||
return { valid: false, errors } | ||
} | ||
|
||
return { valid: true } | ||
} |