plugin-git-manager 1.2.23 → 1.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/externalVersion.js +8 -8
- package/dist/locale/en-US.json +4 -3
- package/dist/locale/vi-VN.json +4 -3
- package/dist/locale/zh-CN.json +4 -3
- package/dist/server/actions/git-actions.js +21 -8
- package/dist/server/actions/gitlab-api.js +5 -8
- package/dist/server/actions/poller.js +2 -1
- package/dist/server/actions/review.js +50 -13
- package/dist/server/actions/role-permissions.js +109 -16
- package/dist/server/actions/subtree.js +4 -8
- package/dist/server/migrations/20260730000000-migrate-legacy-repository-permissions.js +23 -7
- package/dist/server/plugin.js +42 -19
- package/dist/server/repository-access.js +505 -27
- package/dist/server/services/registry-content-service.js +137 -22
- package/dist/server/utils/get-repo-account.js +5 -2
- package/dist/server/utils/gitlab-url.js +2 -0
- package/dist/server/utils/redact.js +51 -5
- package/dist/server/utils/url-security.js +109 -0
- package/package.json +1 -1
- package/src/locale/en-US.json +4 -3
- package/src/locale/vi-VN.json +4 -3
- package/src/locale/zh-CN.json +4 -3
- package/src/server/__tests__/git-actions.test.ts +24 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -0
- package/src/server/__tests__/poller.test.ts +37 -0
- package/src/server/__tests__/repository-access.test.ts +695 -1
- package/src/server/__tests__/review.test.ts +137 -0
- package/src/server/__tests__/role-permissions.test.ts +123 -2
- package/src/server/actions/git-actions.ts +33 -10
- package/src/server/actions/gitlab-api.ts +5 -8
- package/src/server/actions/poller.ts +2 -1
- package/src/server/actions/review.ts +74 -15
- package/src/server/actions/role-permissions.ts +136 -14
- package/src/server/actions/subtree.ts +4 -8
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +23 -8
- package/src/server/plugin.ts +46 -25
- package/src/server/repository-access.ts +737 -28
- package/src/server/services/__tests__/registry-content-service.test.ts +209 -13
- package/src/server/services/registry-content-service.ts +184 -30
- package/src/server/utils/__tests__/redact.test.ts +56 -0
- package/src/server/utils/__tests__/url-security.test.ts +85 -0
- package/src/server/utils/get-repo-account.ts +22 -4
- package/src/server/utils/gitlab-url.ts +3 -0
- package/src/server/utils/redact.ts +68 -5
- package/src/server/utils/url-security.ts +95 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { validateRepoUrl } from '../../actions/git-actions';
|
|
4
|
+
import { parseGitLabProject } from '../gitlab-url';
|
|
5
|
+
import { redactCredentialFields } from '../redact';
|
|
6
|
+
import {
|
|
7
|
+
assertUrlHasNoUserInfo,
|
|
8
|
+
containsCredentialBearingUrlField,
|
|
9
|
+
hasUrlUserInfo,
|
|
10
|
+
redactUrlUserInfo,
|
|
11
|
+
URL_USERINFO_NOT_ALLOWED,
|
|
12
|
+
} from '../url-security';
|
|
13
|
+
|
|
14
|
+
const CREDENTIAL_URL = 'https://user:secret@example.test/group/repository.git';
|
|
15
|
+
const USERNAME_ONLY_URL = 'https://user@example.test/group/repository.git';
|
|
16
|
+
const REPOSITORY_URL_FIELDS = new Set(['repoUrl']);
|
|
17
|
+
const ACCOUNT_URL_FIELDS = new Set(['baseUrl']);
|
|
18
|
+
const GIT_CONFIGURATION_URL_FIELDS = new Set(['repoUrl', 'baseUrl']);
|
|
19
|
+
|
|
20
|
+
describe('Git Manager URL credential security', () => {
|
|
21
|
+
it('rejects URLs with a username or password', () => {
|
|
22
|
+
expect(hasUrlUserInfo(CREDENTIAL_URL)).toBe(true);
|
|
23
|
+
expect(hasUrlUserInfo(USERNAME_ONLY_URL)).toBe(true);
|
|
24
|
+
expect(() => assertUrlHasNoUserInfo(CREDENTIAL_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
25
|
+
expect(() => assertUrlHasNoUserInfo(USERNAME_ONLY_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it.each([
|
|
29
|
+
['direct repository URL', { repoUrl: CREDENTIAL_URL }, REPOSITORY_URL_FIELDS],
|
|
30
|
+
['dotted repository URL', { 'values.repoUrl': CREDENTIAL_URL }, REPOSITORY_URL_FIELDS],
|
|
31
|
+
['bracket account URL', { 'values[baseUrl]': USERNAME_ONLY_URL }, ACCOUNT_URL_FIELDS],
|
|
32
|
+
['nested account URL', { values: { updateAssociationValues: { baseUrl: CREDENTIAL_URL } } }, ACCOUNT_URL_FIELDS],
|
|
33
|
+
[
|
|
34
|
+
'repository association account URL',
|
|
35
|
+
{ values: { gitAccount: { baseUrl: CREDENTIAL_URL } } },
|
|
36
|
+
GIT_CONFIGURATION_URL_FIELDS,
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
'account association repository URL',
|
|
40
|
+
{ values: { repositories: [{ repoUrl: CREDENTIAL_URL }] } },
|
|
41
|
+
GIT_CONFIGURATION_URL_FIELDS,
|
|
42
|
+
],
|
|
43
|
+
['serialized query values', JSON.stringify({ values: { repoUrl: CREDENTIAL_URL } }), REPOSITORY_URL_FIELDS],
|
|
44
|
+
])('finds a credential-bearing URL in %s', (_source, value, fields) => {
|
|
45
|
+
expect(containsCredentialBearingUrlField(value, fields)).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('allows clean URLs and ignores other field names', () => {
|
|
49
|
+
expect(
|
|
50
|
+
containsCredentialBearingUrlField(
|
|
51
|
+
{ values: { repoUrl: 'https://example.test/group/repository.git' } },
|
|
52
|
+
REPOSITORY_URL_FIELDS,
|
|
53
|
+
),
|
|
54
|
+
).toBe(false);
|
|
55
|
+
expect(containsCredentialBearingUrlField({ otherUrl: CREDENTIAL_URL }, REPOSITORY_URL_FIELDS)).toBe(false);
|
|
56
|
+
expect(() => validateRepoUrl('https://example.test/group/repository.git')).not.toThrow();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('rejects credential-bearing URLs in Git entry points', () => {
|
|
60
|
+
expect(() => validateRepoUrl(CREDENTIAL_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
61
|
+
expect(() => parseGitLabProject(USERNAME_ONLY_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('redacts userinfo from nested repository and account responses', () => {
|
|
65
|
+
const response = {
|
|
66
|
+
data: {
|
|
67
|
+
repoUrl: CREDENTIAL_URL,
|
|
68
|
+
gitAccount: {
|
|
69
|
+
baseUrl: USERNAME_ONLY_URL,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
redactCredentialFields(response);
|
|
75
|
+
|
|
76
|
+
expect(response.data.repoUrl).toBe('https://***:***@example.test/group/repository.git');
|
|
77
|
+
expect(response.data.gitAccount.baseUrl).toBe('https://***:***@example.test/group/repository.git');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('does not leak a password segment when legacy userinfo contains another at sign', () => {
|
|
81
|
+
expect(redactUrlUserInfo('https://user:secret@still-secret@example.test/repository.git')).toBe(
|
|
82
|
+
'https://***:***@example.test/repository.git',
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { assertUrlHasNoUserInfo } from './url-security';
|
|
2
|
+
|
|
1
3
|
export interface GitAccountCredentials {
|
|
2
4
|
pat: string;
|
|
3
5
|
username: string;
|
|
@@ -5,19 +7,35 @@ export interface GitAccountCredentials {
|
|
|
5
7
|
provider: string;
|
|
6
8
|
}
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
type RecordGetter = {
|
|
11
|
+
get(attribute: string): unknown;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type GitAccountDatabase = {
|
|
15
|
+
getRepository(name: 'gitAccounts'): {
|
|
16
|
+
findOne(input: { filterByTk: number | string }): Promise<RecordGetter | null>;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export async function getRepoAccount(
|
|
21
|
+
db: GitAccountDatabase,
|
|
22
|
+
repo: RecordGetter,
|
|
23
|
+
): Promise<GitAccountCredentials | null> {
|
|
24
|
+
const gitAccountId = repo.get('gitAccountId');
|
|
25
|
+
if (typeof gitAccountId !== 'number' && typeof gitAccountId !== 'string') return null;
|
|
11
26
|
|
|
12
27
|
const account = await db.getRepository('gitAccounts').findOne({
|
|
13
28
|
filterByTk: gitAccountId,
|
|
14
29
|
});
|
|
15
30
|
if (!account) return null;
|
|
16
31
|
|
|
32
|
+
const baseUrl = ((account.get('baseUrl') as string) || '').trim() || null;
|
|
33
|
+
if (baseUrl) assertUrlHasNoUserInfo(baseUrl);
|
|
34
|
+
|
|
17
35
|
return {
|
|
18
36
|
pat: ((account.get('pat') as string) || '').trim(),
|
|
19
37
|
username: ((account.get('username') as string) || '').trim(),
|
|
20
|
-
baseUrl
|
|
38
|
+
baseUrl,
|
|
21
39
|
provider: ((account.get('provider') as string) || 'gitlab').trim(),
|
|
22
40
|
};
|
|
23
41
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { assertUrlHasNoUserInfo } from './url-security';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Shared utility for parsing GitLab repository URLs.
|
|
3
5
|
* Extracted to avoid duplicating URL-parsing logic across
|
|
@@ -21,6 +23,7 @@ export interface GitLabProject {
|
|
|
21
23
|
* @throws Error if the URL cannot be parsed or has no project path
|
|
22
24
|
*/
|
|
23
25
|
export function parseGitLabProject(repoUrl: string): GitLabProject {
|
|
26
|
+
assertUrlHasNoUserInfo(repoUrl);
|
|
24
27
|
const url = new URL(repoUrl);
|
|
25
28
|
// Remove .git suffix and leading slash
|
|
26
29
|
const projectPath = url.pathname.replace(/\.git$/, '').replace(/^\//, '');
|
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
import { redactUrlUserInfo } from './url-security';
|
|
2
|
+
|
|
3
|
+
export const REDACTED_PAT = '••••••••';
|
|
4
|
+
|
|
5
|
+
const GIT_MANAGER_RESOURCE_SEGMENTS = new Set([
|
|
6
|
+
'gitManager',
|
|
7
|
+
'gitRepositories',
|
|
8
|
+
'gitAccounts',
|
|
9
|
+
'gitReviewFlows',
|
|
10
|
+
'gitCodeReviews',
|
|
11
|
+
'gitSubtreeConfigs',
|
|
12
|
+
'gitSubtreeRuns',
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Association routes use names such as `gitAccounts.1.repositories`, not the
|
|
17
|
+
* raw collection name. Redact every Git Manager resource response so those
|
|
18
|
+
* routes cannot bypass credential scrubbing merely because their name is
|
|
19
|
+
* nested.
|
|
20
|
+
*/
|
|
21
|
+
export function isGitManagerResourceResponse(resourceName: unknown): boolean {
|
|
22
|
+
return (
|
|
23
|
+
typeof resourceName === 'string' &&
|
|
24
|
+
resourceName.split(/[.[\],:/()=\s]+/).some((segment) => GIT_MANAGER_RESOURCE_SEGMENTS.has(segment))
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
1
28
|
/**
|
|
2
29
|
* Redact embedded credentials from URLs in arbitrary strings.
|
|
3
30
|
* Matches `scheme://user:password@host` and replaces with `scheme://***:***@host`.
|
|
@@ -7,7 +34,7 @@
|
|
|
7
34
|
*/
|
|
8
35
|
export function redactPat(s: unknown): string {
|
|
9
36
|
if (typeof s !== 'string') return s == null ? '' : String(s);
|
|
10
|
-
return
|
|
37
|
+
return redactUrlUserInfo(s);
|
|
11
38
|
}
|
|
12
39
|
|
|
13
40
|
/**
|
|
@@ -16,9 +43,45 @@ export function redactPat(s: unknown): string {
|
|
|
16
43
|
*/
|
|
17
44
|
export function redactError<T>(err: T): T {
|
|
18
45
|
if (!err || typeof err !== 'object') return err;
|
|
19
|
-
const
|
|
20
|
-
if (typeof
|
|
21
|
-
if (typeof
|
|
22
|
-
if (typeof
|
|
46
|
+
const error = err as { message?: unknown; stderr?: unknown; stdout?: unknown };
|
|
47
|
+
if (typeof error.message === 'string') error.message = redactPat(error.message);
|
|
48
|
+
if (typeof error.stderr === 'string') error.stderr = redactPat(error.stderr);
|
|
49
|
+
if (typeof error.stdout === 'string') error.stdout = redactPat(error.stdout);
|
|
23
50
|
return err;
|
|
24
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Redact PAT fields anywhere in a serializable API response. Repository
|
|
55
|
+
* responses can contain a nested `gitAccount` (and Sequelize's nested
|
|
56
|
+
* `dataValues`), so a shallow top-level scrub is not sufficient.
|
|
57
|
+
*/
|
|
58
|
+
export function redactCredentialFields(value: unknown): void {
|
|
59
|
+
const visited = new WeakSet<object>();
|
|
60
|
+
|
|
61
|
+
const visit = (current: unknown): void => {
|
|
62
|
+
if (!current || typeof current !== 'object' || visited.has(current)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
visited.add(current);
|
|
66
|
+
|
|
67
|
+
if (Array.isArray(current)) {
|
|
68
|
+
current.forEach(visit);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const record = current as Record<string, unknown>;
|
|
73
|
+
for (const [key, nestedValue] of Object.entries(record)) {
|
|
74
|
+
if (key === 'pat') {
|
|
75
|
+
record[key] = REDACTED_PAT;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if ((key === 'repoUrl' || key === 'baseUrl') && typeof nestedValue === 'string') {
|
|
79
|
+
record[key] = redactUrlUserInfo(nestedValue);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
visit(nestedValue);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
visit(value);
|
|
87
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export const URL_USERINFO_NOT_ALLOWED = 'Credential-bearing URLs are not allowed';
|
|
2
|
+
|
|
3
|
+
function pathSegments(value: string): string[] {
|
|
4
|
+
return value.split(/[.[\],:/()=\s'"]+/);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function parseStructuredValue(value: string): unknown {
|
|
8
|
+
const trimmed = value.trim();
|
|
9
|
+
if (!trimmed.startsWith('{') && !trimmed.startsWith('[')) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(trimmed);
|
|
15
|
+
} catch {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function hasUrlUserInfo(value: unknown): boolean {
|
|
21
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const url = new URL(value.trim());
|
|
27
|
+
return Boolean(url.username || url.password);
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function assertUrlHasNoUserInfo(value: unknown): void {
|
|
34
|
+
if (hasUrlUserInfo(value)) {
|
|
35
|
+
throw new Error(URL_USERINFO_NOT_ALLOWED);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function containsUrlUserInfo(value: unknown, visited = new WeakSet<object>()): boolean {
|
|
40
|
+
if (typeof value === 'string') {
|
|
41
|
+
return hasUrlUserInfo(value);
|
|
42
|
+
}
|
|
43
|
+
if (!value || typeof value !== 'object' || visited.has(value)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
visited.add(value);
|
|
47
|
+
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
return value.some((item) => containsUrlUserInfo(item, visited));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return Object.values(value as Record<string, unknown>).some((item) => containsUrlUserInfo(item, visited));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Generic NocoBase actions can place values directly, inside `values`, or in
|
|
57
|
+
* dotted/bracket paths that UpdateGuard normalizes later. Find userinfo only
|
|
58
|
+
* when it belongs to one of the URL-bearing configuration fields.
|
|
59
|
+
*/
|
|
60
|
+
export function containsCredentialBearingUrlField(
|
|
61
|
+
value: unknown,
|
|
62
|
+
fieldNames: ReadonlySet<string>,
|
|
63
|
+
visited = new WeakSet<object>(),
|
|
64
|
+
): boolean {
|
|
65
|
+
if (typeof value === 'string') {
|
|
66
|
+
const structuredValue = parseStructuredValue(value);
|
|
67
|
+
return structuredValue ? containsCredentialBearingUrlField(structuredValue, fieldNames, visited) : false;
|
|
68
|
+
}
|
|
69
|
+
if (!value || typeof value !== 'object' || visited.has(value)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
visited.add(value);
|
|
73
|
+
|
|
74
|
+
if (Array.isArray(value)) {
|
|
75
|
+
return value.some((item) => containsCredentialBearingUrlField(item, fieldNames, visited));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return Object.entries(value as Record<string, unknown>).some(([key, item]) => {
|
|
79
|
+
if (pathSegments(key).some((segment) => fieldNames.has(segment)) && containsUrlUserInfo(item)) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return containsCredentialBearingUrlField(item, fieldNames, visited);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Preserve the rest of a URL while masking URL userinfo in legacy data or an
|
|
88
|
+
* accidentally nested API response.
|
|
89
|
+
*/
|
|
90
|
+
export function redactUrlUserInfo(value: string): string {
|
|
91
|
+
// Userinfo may itself contain an unescaped `@`; match through the final
|
|
92
|
+
// authority `@` rather than stopping at the first one and leaking part of
|
|
93
|
+
// a password in a malformed or legacy URL.
|
|
94
|
+
return value.replace(/([a-z][a-z\d+.-]*:\/\/)([^/?#\s]+)@/gi, '$1***:***@');
|
|
95
|
+
}
|