Skip to content
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

fix: Add line beginning to origin regex #2876

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions packages/snaps-utils/src/json-rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ describe('isOriginAllowed', () => {
expect(isOriginAllowed(origins, SubjectType.Website, 'bar')).toBe(false);
});

it('matches full string', () => {
const origins: RpcOrigins = {
allowedOrigins: ['https://metamask.io'],
};
expect(
isOriginAllowed(origins, SubjectType.Website, 'https://notmetamask.io'),
).toBe(false);
});

it('supports wildcards', () => {
const origins: RpcOrigins = {
allowedOrigins: ['*'],
Expand Down Expand Up @@ -195,7 +204,7 @@ describe('isOriginAllowed', () => {

it('supports partial strings with wildcards', () => {
const origins: RpcOrigins = {
allowedOrigins: ['*.metamask.io'],
allowedOrigins: ['https://*.metamask.io'],
};

expect(
Expand All @@ -219,7 +228,7 @@ describe('isOriginAllowed', () => {

it('supports multiple wildcards', () => {
const origins: RpcOrigins = {
allowedOrigins: ['*.metamask.*'],
allowedOrigins: ['https://*.metamask.*'],
};

expect(
Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-utils/src/json-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function createOriginRegExp(matcher: string) {
const escaped = matcher.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
// Support wildcards
const regex = escaped.replace(/\\\*/gu, '.*');
return RegExp(`${regex}$`, 'u');
return RegExp(`^${regex}$`, 'u');
}

/**
Expand Down
Loading