From a41ae27882cfd9c33c165c73ffa52c4be2469516 Mon Sep 17 00:00:00 2001 From: dvankeke Date: Mon, 11 May 2026 11:02:24 +0200 Subject: [PATCH 1/2] fix: secure repo url --- src/api-v2.authz.test.ts | 6 +-- src/api.authz.test.ts | 2 +- src/openapi/definitions.yaml | 4 +- src/utils/codeRepoUtils.test.ts | 15 +++++++- src/utils/codeRepoUtils.ts | 67 +++++++++++++++++++++------------ 5 files changed, 62 insertions(+), 32 deletions(-) diff --git a/src/api-v2.authz.test.ts b/src/api-v2.authz.test.ts index 88eb3bc4b..8e4cfd12b 100644 --- a/src/api-v2.authz.test.ts +++ b/src/api-v2.authz.test.ts @@ -4,12 +4,12 @@ import { initApp, loadSpec } from 'src/app' import getToken from 'src/fixtures/jwt' import OtomiStack from 'src/otomi-stack' import request from 'supertest' -import { Git } from './git' -import { getSessionStack } from './middleware' -import * as getValuesSchemaModule from './utils' import TestAgent from 'supertest/lib/agent' import { FileStore } from './fileStore/file-store' +import { Git } from './git' +import { getSessionStack } from './middleware' import { AplKind } from './otomi-models' +import * as getValuesSchemaModule from './utils' const platformAdminToken = getToken(['platform-admin']) const teamAdminToken = getToken(['team-admin', 'team-team1']) diff --git a/src/api.authz.test.ts b/src/api.authz.test.ts index 9a02ba702..ddc5a4fc9 100644 --- a/src/api.authz.test.ts +++ b/src/api.authz.test.ts @@ -698,7 +698,7 @@ describe('API authz tests', () => { const data = { name: 'demo', gitService: 'github' as 'gitea' | 'github' | 'gitlab', - repositoryUrl: 'https://github.com/buildpacks/samples', + repositoryUrl: 'github.com/buildpacks/samples', private: true, secret: 'demo', } diff --git a/src/openapi/definitions.yaml b/src/openapi/definitions.yaml index 84b4e2f00..9268d1359 100644 --- a/src/openapi/definitions.yaml +++ b/src/openapi/definitions.yaml @@ -940,7 +940,7 @@ replicas: default: 1 repoUrl: description: Path to a remote git repo without protocol. Will use https to access. - pattern: ^(.+@)*([\w\d\.]+)(:[\d]+){0,1}/*(.*)$ + pattern: '^(https://)?(github\.com|gitlab\.com|[^/\s]+\.gitea[^/\s]*)/[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+(?:\.git)?$' type: string x-message: a valid git repo URL example: github.com/example/repo @@ -1099,7 +1099,7 @@ svcPredeployed: url: pattern: ^https?:\/\/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/=]*) type: string - example: https://gituhb.com/example + example: https://github.com/example vaultToken: title: Token type: string diff --git a/src/utils/codeRepoUtils.test.ts b/src/utils/codeRepoUtils.test.ts index 27dbf2c48..a9627e704 100644 --- a/src/utils/codeRepoUtils.test.ts +++ b/src/utils/codeRepoUtils.test.ts @@ -118,11 +118,22 @@ describe('codeRepoUtils', () => { expect(result).toEqual('git@github.com:user/repo.git') }) - it('should normalize HTTPS URL', () => { - const result = normalizeRepoUrl('https://github.com/user/repo', false, false) + it('should normalize protocol-less HTTPS URL', () => { + const result = normalizeRepoUrl('github.com/user/repo', false, false) expect(result).toEqual('https://github.com/user/repo.git') }) + it.each([ + 'javascript:alert(1)', + 'data:text/html,', + 'vbscript:msgbox(1)', + 'ftp://github.com/example/repo', + 'github.com/example', + 'github.com/example/repo