Skip to content

Conversation

@RohitRaj011
Copy link
Contributor

No description provided.

AbhishekA1509 and others added 30 commits July 8, 2025 13:35
into chore/misc-fixes # Please enter a commit message to explain why this merge is
necessary, # especially if it merges an updated upstream into a topic branch. # #
Lines starting with '#' will be ignored, and an empty message aborts # the commit.
import { IconName } from '../Icon'

export const isAWSCodeCommitURL = (url: string = ''): boolean =>
url.includes('git-codecommit.') && url.includes('.amazonaws.com')

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

'
.amazonaws.com
' can be anywhere in the URL, and arbitrary hosts may come before or after it.

Copilot Autofix

AI 3 months ago

To fix the problem, the code should properly parse the input URL and then inspect the host portion to determine whether it matches the structure of an AWS CodeCommit repository. Specifically, rather than checking for the presence of 'git-codecommit.' and '.amazonaws.com' anywhere in the string, the code should extract the host part of the URL, and then check that it ends with something like .amazonaws.com and contains git-codecommit. as its subdomain or prefix.

The best way to do this is to use the built-in Node.js URL constructor for URL parsing, which is available in all modern Node/TypeScript environments, or to use the legacy url module (require('url')) if you need to support older environments. For this code, assuming it's running in a browser-compatible or Node.js context and TypeScript, the global URL class will suffice.

The changes required:

  • In isAWSCodeCommitURL, parse the URL using new URL(url).
  • Check the host property (or hostname) of the parsed URL for the pattern: it starts with git-codecommit. and ends with .amazonaws.com.
  • Add error handling to prevent throwing on invalid URLs (e.g., via try/catch).

Edit only the isAWSCodeCommitURL function in the file src/Shared/Components/GitProviderIcon/utils.ts.


Suggested changeset 1
src/Shared/Components/GitProviderIcon/utils.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Shared/Components/GitProviderIcon/utils.ts b/src/Shared/Components/GitProviderIcon/utils.ts
--- a/src/Shared/Components/GitProviderIcon/utils.ts
+++ b/src/Shared/Components/GitProviderIcon/utils.ts
@@ -18,8 +18,17 @@
 
 import { IconName } from '../Icon'
 
-export const isAWSCodeCommitURL = (url: string = ''): boolean =>
-    url.includes('git-codecommit.') && url.includes('.amazonaws.com')
+export const isAWSCodeCommitURL = (url: string = ''): boolean => {
+    try {
+        const { hostname } = new URL(url);
+        return (
+            hostname.startsWith('git-codecommit.') &&
+            hostname.endsWith('.amazonaws.com')
+        );
+    } catch {
+        return false;
+    }
+}
 
 export const getGitIconName = (repoUrl: string): IconName => {
     if (repoUrl.includes(GitProviderType.GITHUB)) {
EOF
@@ -18,8 +18,17 @@

import { IconName } from '../Icon'

export const isAWSCodeCommitURL = (url: string = ''): boolean =>
url.includes('git-codecommit.') && url.includes('.amazonaws.com')
export const isAWSCodeCommitURL = (url: string = ''): boolean => {
try {
const { hostname } = new URL(url);
return (
hostname.startsWith('git-codecommit.') &&
hostname.endsWith('.amazonaws.com')
);
} catch {
return false;
}
}

export const getGitIconName = (repoUrl: string): IconName => {
if (repoUrl.includes(GitProviderType.GITHUB)) {
Copilot is powered by AI and may make mistakes. Always verify output.
@RohitRaj011 RohitRaj011 merged commit 38fe026 into main Sep 1, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants