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 a check for port wildcards #25294

Merged
merged 15 commits into from
Oct 9, 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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ describe('the authorized urls list logic', () => {
proposedUrl: 'https://not.*.valid.*',
validityMessage: 'Wildcards can only be used for subdomains',
},
{
proposedUrl: 'http://localhost:*',
validityMessage: 'Wildcards are not allowed in the port position',
},
{
proposedUrl: 'http://valid.example.com:*',
validityMessage: 'Wildcards are not allowed in the port position',
},
]

testCases.forEach((testCase) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ export function sanitizePossibleWildCardedURL(url: string): URL {
return new URL(deWildCardedURL)
}

/**
* Checks if the URL has a wildcard (*) in the port position eg http://localhost:*
*/
export function hasPortWildcard(input: string): boolean {
if (!input || typeof input !== 'string') {
return false
}
// This regex matches URLs with a wildcard (*) in the port position
const portWildcardRegex = /^(https?:\/\/[^:/]+):\*(.*)$/
return portWildcardRegex.test(input.trim())
}

export const validateProposedUrl = (
proposedUrl: string,
currentUrls: string[],
Expand All @@ -56,6 +68,10 @@ export const validateProposedUrl = (
return 'Please enter a valid URL'
}

if (hasPortWildcard(proposedUrl)) {
zlwaterfield marked this conversation as resolved.
Show resolved Hide resolved
return 'Wildcards are not allowed in the port position'
}

if (onlyAllowDomains && !isDomain(sanitizePossibleWildCardedURL(proposedUrl))) {
return "Please enter a valid domain (URLs with a path aren't allowed)"
}
Expand Down
Loading