-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow wildcards in allowedOrigins
#2458
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2458 +/- ##
=======================================
Coverage 94.32% 94.33%
=======================================
Files 438 438
Lines 9021 9032 +11
Branches 1382 1383 +1
=======================================
+ Hits 8509 8520 +11
Misses 512 512 ☔ View full report in Codecov by Sentry. |
allowedOrigins: ['https://*', 'npm:*'], | ||
}; | ||
|
||
expect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are maybe a bit more readable with it.each
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find it.each
that readable personally tbh 😅
packages/snaps-utils/src/json-rpc.ts
Outdated
origins.allowedOrigins | ||
?.map(createOriginRegExp) | ||
.some((regex) => regex.test(origin)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid creating regex unnecessarily, what do you think of
function checkOrigin(origin: string, originSpecifier: string) {
if (originSpecifier === '*') {
return true;
}
// Create regex and test.
}
// ...
origins.allowedOrigins?.some((specifier) => checkOrigin(origin, specifier))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I added one more optimization to this
Allow wildcards in
allowedOrigins
by generating a RegExp based on each allowed origin and testing the origin against it.Closes #2457