Skip to content

Commit

Permalink
fix: add a check for port wildcards (#25294)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
zlwaterfield and github-actions[bot] authored Oct 9, 2024
1 parent 417725d commit ffb3ded
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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)) {
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

0 comments on commit ffb3ded

Please sign in to comment.