Skip to content

Commit 5eaf8ba

Browse files
fix regex in response to security scan concern in CI build
1 parent 130493e commit 5eaf8ba

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/shared/MarketplaceValidation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ export function isValidGitRepositoryUrl(url: string): boolean {
2727
// - https://gitlab.com/username/repo
2828
// - https://bitbucket.org/username/repo
2929
const httpsPattern =
30-
/^https?:\/\/[a-zA-Z0-9_.-]+(\.[a-zA-Z0-9_.-]+)*\/[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+(\/.+)*(\.git)?$/
30+
/^https?:\/\/(?:[a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+(?:\/[^/]+)*(?:\.git)?$/
3131

3232
// SSH pattern
3333
// Examples:
3434
// - [email protected]:username/repo.git
3535
// - [email protected]:username/repo.git
36-
const sshPattern = /^git@[a-zA-Z0-9_.-]+(\.[a-zA-Z0-9_.-]+)*:([a-zA-Z0-9_.-]+)\/([a-zA-Z0-9_.-]+)(\.git)?$/
36+
const sshPattern = /^git@(?:[a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+:([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)(?:\.git)?$/
3737

3838
// Git protocol pattern
3939
// Examples:
4040
// - git://github.com/username/repo.git
41-
const gitProtocolPattern = /^git:\/\/[a-zA-Z0-9_.-]+(\.[a-zA-Z0-9_.-]+)*\/[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+(\.git)?$/
41+
const gitProtocolPattern = /^git:\/\/(?:[a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+(?:\.git)?$/
4242

4343
return httpsPattern.test(trimmedUrl) || sshPattern.test(trimmedUrl) || gitProtocolPattern.test(trimmedUrl)
4444
}

0 commit comments

Comments
 (0)