CVE-2024-28175: Insufficient Information (NVD-CWE-noinfo)
value: Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes. Due to the improper URL protocols filtering of links specified in the `link.argocd.argoproj.io` annotations in the application summary component, an attacker can achieve cross-site scripting with elevated permissions. All unpatched versions of Argo CD starting with v1.0.0 are vulnerable to a cross-site scripting (XSS) bug allowing a malicious user to inject a javascript: link in the UI. When clicked by a victim user, the script will execute with the victim's permissions (up to and including admin). This vulnerability allows an attacker to perform arbitrary actions on behalf of the victim via the API, such as creating, modifying, and deleting Kubernetes resources. A patch for this vulnerability has been released in Argo CD versions v2.10.3 v2.9.8, and v2.8.12. There are no completely-safe workarounds besides upgrading. The safest alternative, if upgrading is not possible, would be to create a Kubernetes admission controller to reject any resources with an annotation starting with link.argocd.argoproj.io or reject the resource if the value use an improper URL protocol. This validation will need to be applied in all clusters managed by ArgoCD.


CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
Published: 2024-03-13T21:16Z
Repository: https://github.com/argoproj/argo-cd
Language: Other
Files changed: ui/src/app/applications/components/application-summary/application-summary.tsx, ui/src/app/applications/components/application-urls.test.ts, ui/src/app/applications/components/application-urls.tsx
Commit date: 2024-03-13 14:26:47 -0400
Commit message: Merge pull request from GHSA-jwv5-8mqv-g387

* fix: Validate external URLs for applicatins

Signed-off-by: Ry0taK <49341894+Ry0taK@users.noreply.github.com>

* fix(ui): remove invalid external-link

Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>

* linting

Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>

---------

Signed-off-by: Ry0taK <49341894+Ry0taK@users.noreply.github.com>
Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
Diff: diff --git a/ui/src/app/applications/components/application-summary/application-summary.tsx b/ui/src/app/applications/components/application-summary/application-summary.tsx
index 26773f2d3b..f38a380b50 100644
--- a/ui/src/app/applications/components/application-summary/application-summary.tsx
+++ b/ui/src/app/applications/components/application-summary/application-summary.tsx
@@ -28,10 +28,11 @@ import {Link} from 'react-router-dom';
 import {EditNotificationSubscriptions, useEditNotificationSubscriptions} from './edit-notification-subscriptions';
 import {EditAnnotations} from './edit-annotations';
 
 import './application-summary.scss';
 import {DeepLinks} from '../../../shared/components/deep-links';
+import {ExternalLinks} from '../application-urls';
 
 function swap(array: any[], a: number, b: number) {
     array = array.slice();
     [array[a], array[b]] = [array[b], array[a]];
     return array;
@@ -339,24 +340,23 @@ export const ApplicationSummary = (props: ApplicationSummaryProps) => {
                     {(links: models.LinksResponse) => <DeepLinks links={links.items} />}
                 </DataLoader>
             )
         }
     ];
-
-    const urls = app.status.summary.externalURLs || [];
+    const urls = ExternalLinks(app.status.summary.externalURLs);
     if (urls.length > 0) {
         attributes.push({
             title: 'URLs',
             view: (
                 <React.Fragment>
-                    {urls
-                        .map(item => item.split('|'))
-                        .map((parts, i) => (
-                            <a key={i} href={parts.length > 1 ? parts[1] : parts[0]} target='__blank'>
-                                {parts[0]} &nbsp;
+                    {urls.map((url, i) => {
+                        return (
+                            <a key={i} href={url.ref} target='__blank'>
+                                {url.title} &nbsp;
                             </a>
-                        ))}
+                        );
+                    })}
                 </React.Fragment>
             )
         });
     }
 
diff --git a/ui/src/app/applications/components/application-urls.test.ts b/ui/src/app/applications/components/application-urls.test.ts
index c9063561d0..a3093a5a29 100644
--- a/ui/src/app/applications/components/application-urls.test.ts
+++ b/ui/src/app/applications/components/application-urls.test.ts
@@ -1,14 +1,24 @@
-import {ExternalLink, InvalidExternalLinkError} from './application-urls';
+import { ExternalLink, ExternalLinks, InvalidExternalLinkError } from './application-urls';
 
 test('rejects malicious URLs', () => {
     expect(() => {
         const _ = new ExternalLink('javascript:alert("hi")');
     }).toThrowError(InvalidExternalLinkError);
     expect(() => {
         const _ = new ExternalLink('data:text/html;<h1>hi</h1>');
     }).toThrowError(InvalidExternalLinkError);
+    expect(() => {
+        const _ = new ExternalLink('title|data:text/html;<h1>hi</h1>');
+    }).toThrowError(InvalidExternalLinkError);
+    expect(() => {
+        const _ = new ExternalLink('data:title|data:text/html;<h1>hi</h1>');
+    }).toThrowError(InvalidExternalLinkError);
+
+    expect(() => {
+        const _ = new ExternalLink('data:title|https://localhost:8080/applications');
+    }).not.toThrowError(InvalidExternalLinkError);
 });
 
 test('allows absolute URLs', () => {
     expect(new ExternalLink('https://localhost:8080/applications').ref).toEqual('https://localhost:8080/applications');
 });
@@ -16,5 +26,61 @@ test('allows absolute URLs', () => {
 test('allows relative URLs', () => {
     // @ts-ignore
     window.location = new URL('https://localhost:8080/applications');
     expect(new ExternalLink('/applications').ref).toEqual('/applications');
 });
+
+
+test('URLs format', () => {
+    expect(new ExternalLink('https://localhost:8080/applications')).toEqual({
+        ref: 'https://localhost:8080/applications',
+        title: 'https://localhost:8080/applications',
+    })
+    expect(new ExternalLink('title|https://localhost:8080/applications')).toEqual({
+        ref: 'https://localhost:8080/applications',
+        title: 'title',
+    })
+});
+
+
+test('malicious URLs from list to be removed', () => {
+    const urls: string[] = [
+        'javascript:alert("hi")',
+        'https://localhost:8080/applications',
+    ]
+    const links = ExternalLinks(urls);
+
+    expect(links).toHaveLength(1);
+    expect(links).toContainEqual({
+        ref: 'https://localhost:8080/applications',
+        title: 'https://localhost:8080/applications',
+    });
+});
+
+
+test('list to be sorted', () => {
+    const urls: string[] = [
+        'https://a',
+        'https://b',
+        'a|https://c',
+        'z|https://c',
+        'x|https://d',
+        'x|https://c',
+    ]
+    const links = ExternalLinks(urls);
+
+    // 'a|https://c',
+    // 'x|https://c',
+    // 'x|https://d',
+    // 'z|https://c',
+    // 'https://a',
+    // 'https://b',
+    expect(links).toHaveLength(6);
+    expect(links[0].title).toEqual('a')
+    expect(links[1].title).toEqual('x')
+    expect(links[1].ref).toEqual('https://c')
+    expect(links[2].title).toEqual('x')
+    expect(links[2].ref).toEqual('https://d')
+    expect(links[3].title).toEqual('z')
+    expect(links[4].title).toEqual('https://a')
+    expect(links[5].title).toEqual('https://b')
+});
diff --git a/ui/src/app/applications/components/application-urls.tsx b/ui/src/app/applications/components/application-urls.tsx
index e6dc824581..4e4c6997ce 100644
--- a/ui/src/app/applications/components/application-urls.tsx
+++ b/ui/src/app/applications/components/application-urls.tsx
@@ -27,11 +27,11 @@ export class ExternalLink {
             throw new InvalidExternalLinkError('Invalid URL');
         }
     }
 }
 
-export const ApplicationURLs = ({urls}: {urls: string[]}) => {
+export const ExternalLinks = (urls?: string[]) => {
     const externalLinks: ExternalLink[] = [];
     for (const url of urls || []) {
         try {
             const externalLink = new ExternalLink(url);
             externalLinks.push(externalLink);
@@ -40,20 +40,30 @@ export const ApplicationURLs = ({urls}: {urls: string[]}) => {
         }
     }
 
     // sorted alphabetically & links with titles first
     externalLinks.sort((a, b) => {
-        if (a.title !== '' && b.title !== '') {
+        const hasTitle = (x: ExternalLink): boolean => {
+            return x.title !== x.ref && x.title !== '';
+        };
+
+        if (hasTitle(a) && hasTitle(b) && a.title !== b.title) {
             return a.title > b.title ? 1 : -1;
-        } else if (a.title === '') {
+        } else if (hasTitle(b) && !hasTitle(a)) {
             return 1;
-        } else if (b.title === '') {
+        } else if (hasTitle(a) && !hasTitle(b)) {
             return -1;
         }
         return a.ref > b.ref ? 1 : -1;
     });
 
+    return externalLinks;
+};
+
+export const ApplicationURLs = ({urls}: {urls: string[]}) => {
+    const externalLinks: ExternalLink[] = ExternalLinks(urls);
+
     return (
         ((externalLinks || []).length > 0 && (
             <div className='applications-list__external-links-icon-container'>
                 <a
                     title={externalLinks[0].title}

Vulnerable code: 
    const urls = app.status.summary.externalURLs || [];
                    {urls
                        .map(item => item.split('|'))
                        .map((parts, i) => (
                            <a key={i} href={parts.length > 1 ? parts[1] : parts[0]} target='__blank'>
                                {parts[0]} &nbsp;
                        ))}
import {ExternalLink, InvalidExternalLinkError} from './application-urls';
export const ApplicationURLs = ({urls}: {urls: string[]}) => {
        if (a.title !== '' && b.title !== '') {
        } else if (a.title === '') {
        } else if (b.title === '') {
Fixed code: import {ExternalLinks} from '../application-urls';
    const urls = ExternalLinks(app.status.summary.externalURLs);
                    {urls.map((url, i) => {
                        return (
                            <a key={i} href={url.ref} target='__blank'>
                                {url.title} &nbsp;
                        );
                    })}
import { ExternalLink, ExternalLinks, InvalidExternalLinkError } from './application-urls';
    expect(() => {
        const _ = new ExternalLink('title|data:text/html;<h1>hi</h1>');
    }).toThrowError(InvalidExternalLinkError);
    expect(() => {
        const _ = new ExternalLink('data:title|data:text/html;<h1>hi</h1>');
    }).toThrowError(InvalidExternalLinkError);

    expect(() => {
        const _ = new ExternalLink('data:title|https://localhost:8080/applications');
    }).not.toThrowError(InvalidExternalLinkError);


test('URLs format', () => {
    expect(new ExternalLink('https://localhost:8080/applications')).toEqual({
        ref: 'https://localhost:8080/applications',
        title: 'https://localhost:8080/applications',
    })
    expect(new ExternalLink('title|https://localhost:8080/applications')).toEqual({
        ref: 'https://localhost:8080/applications',
        title: 'title',
    })
});


test('malicious URLs from list to be removed', () => {
    const urls: string[] = [
        'javascript:alert("hi")',
        'https://localhost:8080/applications',
    ]
    const links = ExternalLinks(urls);

    expect(links).toHaveLength(1);
    expect(links).toContainEqual({
        ref: 'https://localhost:8080/applications',
        title: 'https://localhost:8080/applications',
    });
});


test('list to be sorted', () => {
    const urls: string[] = [
        'https://a',
        'https://b',
        'a|https://c',
        'z|https://c',
        'x|https://d',
        'x|https://c',
    ]
    const links = ExternalLinks(urls);

    // 'a|https://c',
    // 'x|https://c',
    // 'x|https://d',
    // 'z|https://c',
    // 'https://a',
    // 'https://b',
    expect(links).toHaveLength(6);
    expect(links[0].title).toEqual('a')
    expect(links[1].title).toEqual('x')
    expect(links[1].ref).toEqual('https://c')
    expect(links[2].title).toEqual('x')
    expect(links[2].ref).toEqual('https://d')
    expect(links[3].title).toEqual('z')
    expect(links[4].title).toEqual('https://a')
    expect(links[5].title).toEqual('https://b')
});
export const ExternalLinks = (urls?: string[]) => {
        const hasTitle = (x: ExternalLink): boolean => {
            return x.title !== x.ref && x.title !== '';
        };

        if (hasTitle(a) && hasTitle(b) && a.title !== b.title) {
        } else if (hasTitle(b) && !hasTitle(a)) {
        } else if (hasTitle(a) && !hasTitle(b)) {
    return externalLinks;
};

export const ApplicationURLs = ({urls}: {urls: string[]}) => {
    const externalLinks: ExternalLink[] = ExternalLinks(urls);