-
Notifications
You must be signed in to change notification settings - Fork 274
[dev] [Marfuen] mariano/cs-176-bug-when-adding-wix-as-a-vendor-the-agent-pulls-in-site-urls #2335
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
Merged
Marfuen
merged 1 commit into
main
from
mariano/cs-176-bug-when-adding-wix-as-a-vendor-the-agent-pulls-in-site-urls
Mar 18, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
119 changes: 119 additions & 0 deletions
119
apps/api/src/trigger/vendor/vendor-risk-assessment/url-validation.spec.ts
This file contains hidden or 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,119 @@ | ||
| import { | ||
| isUrlFromVendorDomain, | ||
| extractVendorDomain, | ||
| validateVendorUrl, | ||
| } from './url-validation'; | ||
|
|
||
| // Mock the logger so tests don't need @trigger.dev/sdk | ||
| jest.mock('@trigger.dev/sdk', () => ({ | ||
| logger: { warn: jest.fn(), info: jest.fn(), debug: jest.fn() }, | ||
| })); | ||
|
|
||
| describe('isUrlFromVendorDomain', () => { | ||
| it('accepts exact domain match', () => { | ||
| expect(isUrlFromVendorDomain('https://wix.com/privacy', 'wix.com')).toBe( | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| it('accepts www subdomain', () => { | ||
| expect( | ||
| isUrlFromVendorDomain('https://www.wix.com/terms', 'wix.com'), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('accepts other subdomains', () => { | ||
| expect( | ||
| isUrlFromVendorDomain('https://trust.wix.com', 'wix.com'), | ||
| ).toBe(true); | ||
| expect( | ||
| isUrlFromVendorDomain('https://security.wix.com/page', 'wix.com'), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects completely different domains', () => { | ||
| expect(isUrlFromVendorDomain('https://x.com/privacy', 'wix.com')).toBe( | ||
| false, | ||
| ); | ||
| expect( | ||
| isUrlFromVendorDomain('https://twitter.com/wix', 'wix.com'), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects domains that end with vendor domain but are different', () => { | ||
| // "notwix.com" ends with "wix.com" as a string, but is a different domain | ||
| expect( | ||
| isUrlFromVendorDomain('https://notwix.com/privacy', 'wix.com'), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it('is case-insensitive', () => { | ||
| expect( | ||
| isUrlFromVendorDomain('https://WWW.WIX.COM/privacy', 'wix.com'), | ||
| ).toBe(true); | ||
| expect( | ||
| isUrlFromVendorDomain('https://wix.com/privacy', 'WIX.COM'), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for invalid URLs', () => { | ||
| expect(isUrlFromVendorDomain('not-a-url', 'wix.com')).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('extractVendorDomain', () => { | ||
| it('extracts domain from full URL', () => { | ||
| expect(extractVendorDomain('https://www.wix.com')).toBe('wix.com'); | ||
| }); | ||
|
|
||
| it('strips www prefix', () => { | ||
| expect(extractVendorDomain('https://www.example.com/path')).toBe( | ||
| 'example.com', | ||
| ); | ||
| }); | ||
|
|
||
| it('handles URLs without protocol', () => { | ||
| expect(extractVendorDomain('wix.com')).toBe('wix.com'); | ||
| expect(extractVendorDomain('www.wix.com')).toBe('wix.com'); | ||
| }); | ||
|
|
||
| it('returns null for invalid input', () => { | ||
| expect(extractVendorDomain('')).toBe(null); | ||
| }); | ||
|
|
||
| it('preserves subdomains other than www', () => { | ||
| expect(extractVendorDomain('https://trust.wix.com')).toBe('trust.wix.com'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('validateVendorUrl', () => { | ||
| it('returns normalized URL for valid vendor URLs', () => { | ||
| expect(validateVendorUrl('https://wix.com/privacy', 'wix.com', 'privacy')).toBe( | ||
| 'https://wix.com/privacy', | ||
| ); | ||
| }); | ||
|
|
||
| it('returns null for URLs from wrong domain', () => { | ||
| expect( | ||
| validateVendorUrl('https://x.com/privacy', 'wix.com', 'privacy'), | ||
| ).toBe(null); | ||
| }); | ||
|
|
||
| it('returns null for empty/null input', () => { | ||
| expect(validateVendorUrl(null, 'wix.com', 'test')).toBe(null); | ||
| expect(validateVendorUrl(undefined, 'wix.com', 'test')).toBe(null); | ||
| expect(validateVendorUrl('', 'wix.com', 'test')).toBe(null); | ||
| }); | ||
|
|
||
| it('normalizes bare domains by adding https', () => { | ||
| expect(validateVendorUrl('wix.com/terms', 'wix.com', 'terms')).toBe( | ||
| 'https://wix.com/terms', | ||
| ); | ||
| }); | ||
|
|
||
| it('accepts subdomain URLs', () => { | ||
| expect( | ||
| validateVendorUrl('https://trust.wix.com', 'wix.com', 'trust'), | ||
| ).toBe('https://trust.wix.com/'); | ||
| }); | ||
| }); |
76 changes: 76 additions & 0 deletions
76
apps/api/src/trigger/vendor/vendor-risk-assessment/url-validation.ts
This file contains hidden or 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,76 @@ | ||
| import { logger } from '@trigger.dev/sdk'; | ||
|
|
||
| /** | ||
| * Checks whether a URL belongs to the given vendor domain (including subdomains). | ||
| * For example, if vendorDomain is "wix.com", accepts "wix.com", "www.wix.com", | ||
| * "trust.wix.com", but rejects "x.com" or "notwix.com". | ||
| */ | ||
| export function isUrlFromVendorDomain( | ||
| url: string, | ||
| vendorDomain: string, | ||
| ): boolean { | ||
| try { | ||
| const hostname = new URL(url).hostname.toLowerCase(); | ||
| const domain = vendorDomain.toLowerCase(); | ||
| // Exact match or subdomain match (e.g., trust.wix.com for wix.com) | ||
| return hostname === domain || hostname.endsWith(`.${domain}`); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the vendor domain from a website URL, stripping www. prefix. | ||
| * Returns null if the URL is invalid. | ||
| */ | ||
| export function extractVendorDomain( | ||
| website: string, | ||
| ): string | null { | ||
| try { | ||
| const urlObj = new URL( | ||
| /^https?:\/\//i.test(website) ? website : `https://${website}`, | ||
| ); | ||
| return urlObj.hostname.toLowerCase().replace(/^www\./, ''); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Validates and filters a URL, ensuring it belongs to the vendor domain. | ||
| * Returns null (with a warning log) if the URL is from a different domain. | ||
| */ | ||
| export function validateVendorUrl( | ||
| url: string | null | undefined, | ||
| vendorDomain: string, | ||
| label: string, | ||
| ): string | null { | ||
| if (!url) return null; | ||
| const trimmed = url.trim(); | ||
| if (!trimmed) return null; | ||
|
|
||
| // Normalize: add https if looks like a bare domain | ||
| const looksLikeDomain = | ||
| !/^https?:\/\//i.test(trimmed) && | ||
| /^[a-z0-9.-]+\.[a-z]{2,}([/].*)?$/i.test(trimmed); | ||
| const candidate = looksLikeDomain ? `https://${trimmed}` : trimmed; | ||
|
|
||
| try { | ||
| const u = new URL(candidate); | ||
| if (!['http:', 'https:'].includes(u.protocol)) return null; | ||
| const normalized = u.toString(); | ||
|
|
||
| if (!isUrlFromVendorDomain(normalized, vendorDomain)) { | ||
| logger.warn('Filtered out URL from wrong domain', { | ||
| vendorDomain, | ||
| label, | ||
| url: normalized, | ||
| }); | ||
| return null; | ||
| } | ||
|
|
||
| return normalized; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.