Skip to content

Commit 4535615

Browse files
committed
fix: add allowlist
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 523fa7e commit 4535615

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

services/apps/packages_worker/src/maven/__tests__/normalize.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,25 @@ describe('normalizeScmUrl', () => {
221221
expect(normalizeScmUrl('https://gitlab.com:443/foo/bar')).toBe('https://gitlab.com/foo/bar')
222222
})
223223

224+
it('recovers git://host:owner/repo SCP colon form', () => {
225+
expect(normalizeScmUrl('git://github.com:appendium/objectlabkit.git')).toBe(
226+
'https://github.com/appendium/objectlabkit',
227+
)
228+
})
229+
224230
it('accepts allowlisted self-hosted GitLab/Gitea hosts', () => {
225231
expect(normalizeScmUrl('https://git.neckar.it/neckarit/neckar-hub')).toBe(
226232
'https://git.neckar.it/neckarit/neckar-hub',
227233
)
228234
expect(normalizeScmUrl('scm:git:https://gitlab.inria.fr/owner/repo.git')).toBe(
229235
'https://gitlab.inria.fr/owner/repo',
230236
)
237+
expect(normalizeScmUrl('https://git.iem.at/owner/repo')).toBe('https://git.iem.at/owner/repo')
231238
})
232239

233-
it('still returns null for hosts not in the allowlist', () => {
240+
it('still returns null for internal or non-allowlisted hosts', () => {
234241
expect(normalizeScmUrl('https://git.corp.adobe.com/team/project')).toBeNull()
242+
expect(normalizeScmUrl('https://gitlab.alibaba-inc.com/team/project')).toBeNull()
235243
expect(normalizeScmUrl('https://android.googlesource.com/platform/tools/base')).toBeNull()
236244
})
237245
})

services/apps/packages_worker/src/maven/extract.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,21 @@ const SCM_HOSTS = new Set([
479479
'codeberg.org',
480480
// Self-hosted GitLab / Gitea instances seen in Maven POMs with clean
481481
// /<owner>/<repo> paths (same shape as gitlab.com — handled by the generic logic).
482+
// Internal-only hosts (git.corp.adobe.com, gitlab.alibaba-inc.com) are excluded:
483+
// their links are unreachable for consumers. The ≥2-segment owner/repo requirement
484+
// acts as a safety net so a mis-classified host yields NULL, never a junk link.
482485
'gitlab.smartb.city',
483486
'gitlab.ow2.org',
484487
'gitlab.nuiton.org',
485488
'gitlab.inria.fr',
486489
'git.neckar.it',
490+
'git.iem.at',
491+
'git.oschina.net',
492+
'git.i-novus.ru',
493+
'gitlab.protontech.ch',
494+
'git.catchpoint.net',
495+
'git.dorkbox.com',
496+
'git.adorsys.de',
487497
])
488498

489499
/** Hosts whose owner/repo path is case-insensitive and should be lower-cased. */
@@ -529,13 +539,14 @@ export function normalizeScmUrl(raw: string | null): string | null {
529539
// ssh://git@host/… → https://host/…
530540
s = s.replace(/^ssh:\/\/git@([^/]+)\//, 'https://$1/')
531541

542+
// git:// → https://, and upgrade http:// → https:// — done before the SCP-colon
543+
// rule below so that git://host:owner/repo is normalised too.
544+
s = s.replace(/^git:\/\//, 'https://').replace(/^http:\/\//, 'https://')
545+
532546
// scheme://host:owner/repo → scheme://host/owner/repo — the colon is an SCP path
533547
// separator, not a port (guarded by \D so real numeric ports are left intact).
534548
s = s.replace(/^(https?):\/\/([^:/]+):(?=\D)/, '$1://$2/')
535549

536-
// git:// → https://, and upgrade http:// → https://
537-
s = s.replace(/^git:\/\//, 'https://').replace(/^http:\/\//, 'https://')
538-
539550
// No scheme at all (e.g. "github.com/owner/repo") → assume https
540551
if (!s.includes('://')) {
541552
// Bare SCP form "host:owner/repo" → "host/owner/repo" before assuming https.

0 commit comments

Comments
 (0)