Repository navigation
[CONS-1091] Harbor renders catalog links without checking they are web URLs #209
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
defunctl
merged 10 commits into
experiment/software-stack
from
fix/CONS-1091-web-url-links
Oct 11, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b337580
[CONS-1091] Render catalog links only when they are http(s)
johnhooks 2463ebf
Build frontend assets
johnhooks 1eb0310
Trim the link check comments to match upsell-offers
johnhooks d5337d0
Build frontend assets
johnhooks 0d1df63
Merge branch 'experiment/software-stack' into fix/CONS-1091-web-url-l…
johnhooks a7d102f
[CONS-1091] Sanitize catalog tier links when Harbor reads the catalog
johnhooks 6c72792
Reword catalog link comments for the spell check
johnhooks b6561de
Run the non-web catalog link cases through a data provider
johnhooks 124c600
[CONS-1091] Hide activation and subscription links that are not http(s)
johnhooks 7076268
Build frontend assets
johnhooks 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '2e6029161561cf03b75b'); | ||
| <?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'e6c20842b642780c13e2'); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| <?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '89e6f0b1ba0650424eeb'); | ||
| <?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '60929e0f22c74b6d0c3a'); |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Catalog and activation links, accepted only as http(s) so Portal data never renders as a script link. | ||
| * | ||
| * @package LiquidWeb\Harbor | ||
| */ | ||
|
|
||
| /** | ||
| * Parse a link, or return undefined when it is missing or not http(s). | ||
| */ | ||
| export function parseWebUrl( href: string | null | undefined ): URL | undefined { | ||
| const trimmed = href?.trim(); | ||
| if ( ! trimmed ) { | ||
| return undefined; | ||
| } | ||
|
|
||
| try { | ||
| const url = new URL( trimmed ); | ||
| return url.protocol === 'https:' || url.protocol === 'http:' ? url : undefined; | ||
| } catch { | ||
| return undefined; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The trimmed link when it is http(s), otherwise undefined. | ||
| */ | ||
| export function webUrl( href: string | null | undefined ): string | undefined { | ||
| return parseWebUrl( href ) ? href?.trim() : undefined; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| import { LegacyLicenseBanner } from '@/components/molecules/LegacyLicenseBanner'; | ||
|
|
||
| jest.mock( '@wordpress/data', () => ( { useSelect: jest.fn() } ) ); | ||
| jest.mock( '@/store', () => ( { store: { name: 'harbor' } } ) ); | ||
|
|
||
| let mockSubscriptionsUrl: string | null = 'https://portal.example/subscriptions/'; | ||
| jest.mock( '@/lib/harbor-data', () => ( { | ||
| getHarborDataValue: () => mockSubscriptionsUrl, | ||
| } ) ); | ||
|
|
||
| describe( 'LegacyLicenseBanner', () => { | ||
| beforeEach( () => { | ||
| ( useSelect as jest.Mock ).mockReturnValue( true ); | ||
| } ); | ||
|
|
||
| it( 'links to the subscriptions page', () => { | ||
| mockSubscriptionsUrl = 'https://portal.example/subscriptions/'; | ||
| render( <LegacyLicenseBanner /> ); | ||
| expect( screen.getByRole( 'link', { name: 'switching to a unified license' } ).getAttribute( 'href' ) ).toBe( 'https://portal.example/subscriptions/' ); | ||
| } ); | ||
|
|
||
| it.each( [ 'javascript:alert(1)//', 'not a url', null ] )( 'renders nothing for a rejected subscriptions URL %p', ( url ) => { | ||
| mockSubscriptionsUrl = url; | ||
| const { container } = render( <LegacyLicenseBanner /> ); | ||
| expect( container.innerHTML ).toBe( '' ); | ||
| } ); | ||
| } ); |
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,41 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { LicenseProductCard } from '@/components/molecules/LicenseProductCard'; | ||
| import type { LicenseProduct } from '@/types/api'; | ||
|
|
||
| const unactivated = { | ||
| product_slug: 'kadence', | ||
| tier: 'pro', | ||
| status: 'active', | ||
| expires: '2099-12-31 23:59:59', | ||
| activations: { site_limit: 1, active_count: 0, over_limit: false, domains: [] }, | ||
| capabilities: [], | ||
| activated_here: false, | ||
| validation_status: 'not_activated', | ||
| is_valid: false, | ||
| } as LicenseProduct; | ||
|
|
||
| function renderCard( activationUrl: string | null ) { | ||
| render( | ||
| <LicenseProductCard | ||
| productSlug="kadence" | ||
| productName="Kadence" | ||
| tiers={ [ unactivated ] } | ||
| tierNameMap={ { pro: 'Pro' } } | ||
| activationUrl={ activationUrl } | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| describe( 'LicenseProductCard activation', () => { | ||
| it( 'links an unactivated tier to the activation URL with its SKU', () => { | ||
| renderCard( 'https://portal.example/activate' ); | ||
| const url = new URL( screen.getByRole( 'link', { name: 'Activate' } ).getAttribute( 'href' )! ); | ||
| expect( url.searchParams.get( 'sku' ) ).toBe( 'kadence:pro' ); | ||
| } ); | ||
|
|
||
| it.each( [ 'javascript:alert(1)//', 'not a url', null ] )( 'hides Activate for a rejected activation URL %p', ( url ) => { | ||
| renderCard( url ); | ||
| expect( screen.queryByRole( 'link', { name: 'Activate' } ) ).toBeNull(); | ||
| expect( screen.queryByText( 'Activate' ) ).toBeNull(); | ||
| } ); | ||
| } ); |
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,43 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { LicenseSection } from '@/components/organisms/LicenseSection'; | ||
| import type { LicenseProduct } from '@/types/api'; | ||
|
|
||
| jest.mock( '@/components/molecules/LicenseKeyInput', () => ( { LicenseKeyInput: () => null } ) ); | ||
| jest.mock( '@/components/molecules/LicenseProductCard', () => ( { LicenseProductCard: () => null } ) ); | ||
|
|
||
| let mockSubscriptionsUrl: string | null = 'https://portal.example/subscriptions/'; | ||
| jest.mock( '@/lib/harbor-data', () => ( { | ||
| getHarborDataValue: () => mockSubscriptionsUrl, | ||
| } ) ); | ||
|
|
||
| const purchase = { product_slug: 'kadence', tier: 'pro', activated_here: true, is_valid: true } as LicenseProduct; | ||
|
|
||
| function renderSection() { | ||
| render( | ||
| <LicenseSection | ||
| licenseKey="LWSW-TEST" | ||
| licenseProducts={ [ purchase ] } | ||
| tierNameMap={ { pro: 'Pro' } } | ||
| tierRankMap={ { pro: 2 } } | ||
| onRemove={ async () => null } | ||
| onRefresh={ async () => {} } | ||
| isRefreshing={ false } | ||
| isLoading={ false } | ||
| activationUrl={ null } | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| describe( 'LicenseSection manage link', () => { | ||
| it( 'links to the subscriptions page', () => { | ||
| mockSubscriptionsUrl = 'https://portal.example/subscriptions/'; | ||
| renderSection(); | ||
| expect( screen.getByRole( 'link', { name: 'Manage license in Nexcess' } ).getAttribute( 'href' ) ).toBe( 'https://portal.example/subscriptions/' ); | ||
| } ); | ||
|
|
||
| it.each( [ 'javascript:alert(1)//', 'not a url', null ] )( 'hides the manage link for a rejected subscriptions URL %p', ( url ) => { | ||
| mockSubscriptionsUrl = url; | ||
| renderSection(); | ||
| expect( screen.queryByText( 'Manage license in Nexcess' ) ).toBeNull(); | ||
| } ); | ||
| } ); |
Oops, something went wrong.
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.