Skip to content

Commit

Permalink
feat(connect): trust localhost subdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan committed Jan 31, 2025
1 parent 49fd2cb commit c148eeb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/connect/src/utils/__tests__/urlUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('utils/urlUtils', () => {

it('getHost', () => {
expect(getHost('http://localhost:8088/')).toEqual('localhost');
expect(getHost('http://subdomain.localhost:8088/')).toEqual('localhost');
expect(getHost('file://index.html')).toEqual(undefined);
expect(getHost('https://trezor.io')).toEqual('trezor.io');
expect(getHost('https://connect.trezor.io')).toEqual('trezor.io');
Expand Down
3 changes: 3 additions & 0 deletions packages/connect/src/utils/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const getHost = (url: unknown) => {
if (uri) {
const parts = uri.split('.');

// allow localhost subdomains
if (parts[parts.length - 1] === 'localhost') return 'localhost';

return parts.length > 2
? // slice subdomain
parts.slice(parts.length - 2, parts.length).join('.')
Expand Down

0 comments on commit c148eeb

Please sign in to comment.