plugin-git-manager 1.2.21 → 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.
Files changed (50) hide show
  1. package/dist/client/{434.1d19d4d6acc114f1.js → 434.b2eeaaef33aae6e0.js} +1 -1
  2. package/dist/client/index.js +1 -1
  3. package/dist/client-v2/{434.f8836ea116648de1.js → 434.7a27051db18526c0.js} +1 -1
  4. package/dist/client-v2/index.js +1 -1
  5. package/dist/externalVersion.js +8 -8
  6. package/dist/locale/en-US.json +4 -3
  7. package/dist/locale/vi-VN.json +4 -3
  8. package/dist/locale/zh-CN.json +4 -3
  9. package/dist/server/actions/git-actions.js +21 -8
  10. package/dist/server/actions/gitlab-api.js +5 -8
  11. package/dist/server/actions/poller.js +2 -1
  12. package/dist/server/actions/review.js +50 -13
  13. package/dist/server/actions/role-permissions.js +217 -54
  14. package/dist/server/actions/subtree.js +4 -8
  15. package/dist/server/migrations/20260730000000-migrate-legacy-repository-permissions.js +94 -0
  16. package/dist/server/plugin.js +44 -19
  17. package/dist/server/repository-access.js +570 -0
  18. package/dist/server/services/registry-content-service.js +137 -22
  19. package/dist/server/utils/get-repo-account.js +5 -2
  20. package/dist/server/utils/gitlab-url.js +2 -0
  21. package/dist/server/utils/redact.js +51 -5
  22. package/dist/server/utils/url-security.js +109 -0
  23. package/package.json +1 -1
  24. package/src/client/components/RepositoryConfig.tsx +4 -1
  25. package/src/locale/en-US.json +4 -3
  26. package/src/locale/vi-VN.json +4 -3
  27. package/src/locale/zh-CN.json +4 -3
  28. package/src/server/__tests__/git-actions.test.ts +24 -0
  29. package/src/server/__tests__/plugin-url-security.test.ts +17 -0
  30. package/src/server/__tests__/poller.test.ts +37 -0
  31. package/src/server/__tests__/repository-access.test.ts +752 -0
  32. package/src/server/__tests__/review.test.ts +137 -0
  33. package/src/server/__tests__/role-permissions.test.ts +147 -0
  34. package/src/server/actions/git-actions.ts +33 -10
  35. package/src/server/actions/gitlab-api.ts +5 -8
  36. package/src/server/actions/poller.ts +2 -1
  37. package/src/server/actions/review.ts +74 -15
  38. package/src/server/actions/role-permissions.ts +251 -59
  39. package/src/server/actions/subtree.ts +4 -8
  40. package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -0
  41. package/src/server/plugin.ts +48 -24
  42. package/src/server/repository-access.ts +773 -0
  43. package/src/server/services/__tests__/registry-content-service.test.ts +209 -13
  44. package/src/server/services/registry-content-service.ts +184 -30
  45. package/src/server/utils/__tests__/redact.test.ts +56 -0
  46. package/src/server/utils/__tests__/url-security.test.ts +85 -0
  47. package/src/server/utils/get-repo-account.ts +22 -4
  48. package/src/server/utils/gitlab-url.ts +3 -0
  49. package/src/server/utils/redact.ts +68 -5
  50. package/src/server/utils/url-security.ts +95 -0
@@ -1,5 +1,203 @@
1
- function getRecordValue(record: any, key: string) {
2
- return record?.get ? record.get(key) : record?.[key];
1
+ import type { Database, Model } from '@nocobase/database';
2
+
3
+ function getRecordValue(record: unknown, key: string) {
4
+ if (!record || typeof record !== 'object') return undefined;
5
+ const model = record as { get?: (attribute: string) => unknown } & Record<string, unknown>;
6
+ return typeof model.get === 'function' ? model.get(key) : model[key];
7
+ }
8
+
9
+ export const REPOSITORY_READ_ACTIONS = ['list', 'get'] as const;
10
+ export const GIT_READ_ACTIONS = [
11
+ 'status',
12
+ 'log',
13
+ 'branches',
14
+ 'diff',
15
+ 'fileTree',
16
+ 'fileContent',
17
+ 'commitDetail',
18
+ 'mergeRequests',
19
+ 'mergeRequestDetail',
20
+ 'mergeRequestNotes',
21
+ 'pollerStatus',
22
+ 'subtreePreview',
23
+ 'subtreeOptions',
24
+ ] as const;
25
+ export const GIT_WRITE_ACTIONS = [
26
+ 'clone',
27
+ 'pull',
28
+ 'push',
29
+ 'fetch',
30
+ 'checkout',
31
+ 'triggerReview',
32
+ 'reviewApprovePost',
33
+ 'reviewReject',
34
+ 'pollNow',
35
+ 'subtreeRun',
36
+ ] as const;
37
+
38
+ export type RepositoryPermissionScope = {
39
+ ids: Array<number | string>;
40
+ unrestricted: boolean;
41
+ supported: boolean;
42
+ };
43
+
44
+ type ScopeResolution = {
45
+ ids: Set<number | string>;
46
+ unrestricted: boolean;
47
+ supported: boolean;
48
+ };
49
+
50
+ function supportedIds(ids: Iterable<number | string>): ScopeResolution {
51
+ return { ids: new Set(ids), unrestricted: false, supported: true };
52
+ }
53
+
54
+ function unsupportedScope(): ScopeResolution {
55
+ return { ids: new Set(), unrestricted: false, supported: false };
56
+ }
57
+
58
+ function combineScopeBranches(operator: '$and' | '$or', branches: unknown[]): ScopeResolution {
59
+ const resolutions = branches.map(resolveRepositoryScope);
60
+ if (resolutions.some((resolution) => !resolution.supported)) return unsupportedScope();
61
+
62
+ if (operator === '$or') {
63
+ if (resolutions.some((resolution) => resolution.unrestricted)) {
64
+ return { ids: new Set(), unrestricted: true, supported: true };
65
+ }
66
+ return supportedIds(resolutions.flatMap((resolution) => [...resolution.ids]));
67
+ }
68
+
69
+ const restricted = resolutions.filter((resolution) => !resolution.unrestricted);
70
+ if (restricted.length === 0) {
71
+ return { ids: new Set(), unrestricted: true, supported: true };
72
+ }
73
+ const [first, ...rest] = restricted;
74
+ const ids = new Set([...first.ids].filter((id) => rest.every((resolution) => resolution.ids.has(id))));
75
+ return supportedIds(ids);
76
+ }
77
+
78
+ function resolveRepositoryScope(scope: unknown): ScopeResolution {
79
+ if (scope == null) {
80
+ return { ids: new Set(), unrestricted: true, supported: true };
81
+ }
82
+ if (typeof scope !== 'object' || Array.isArray(scope)) return unsupportedScope();
83
+
84
+ const condition = scope as Record<string, unknown>;
85
+ const keys = Object.keys(condition);
86
+ if (keys.length === 0) {
87
+ return { ids: new Set(), unrestricted: true, supported: true };
88
+ }
89
+
90
+ const operator = keys.find((key) => key === '$and' || key === '$or');
91
+ if (operator) {
92
+ if (keys.length !== 1 || !Array.isArray(condition[operator])) return unsupportedScope();
93
+ return combineScopeBranches(operator as '$and' | '$or', condition[operator] as unknown[]);
94
+ }
95
+
96
+ if (keys.length !== 1 || !('id' in condition)) return unsupportedScope();
97
+ const id = condition.id;
98
+ if (typeof id === 'number' || typeof id === 'string') {
99
+ return supportedIds([id]);
100
+ }
101
+ if (!id || typeof id !== 'object' || Array.isArray(id)) return unsupportedScope();
102
+
103
+ const idCondition = id as Record<string, unknown>;
104
+ const idKeys = Object.keys(idCondition);
105
+ if (idKeys.length !== 1) return unsupportedScope();
106
+ const equal = idCondition.$eq;
107
+ if (typeof equal === 'number' || typeof equal === 'string') {
108
+ return supportedIds([equal]);
109
+ }
110
+ const included = idCondition.$in;
111
+ if (Array.isArray(included) && included.every((value) => typeof value === 'number' || typeof value === 'string')) {
112
+ return supportedIds(included as Array<number | string>);
113
+ }
114
+ return unsupportedScope();
115
+ }
116
+
117
+ function actionScope(actionData: Record<string, unknown>): unknown {
118
+ const scopeRow = actionData.scope;
119
+ if (!scopeRow || typeof scopeRow !== 'object') return undefined;
120
+ const scopeRecord = scopeRow as Record<string, unknown>;
121
+ return 'scope' in scopeRecord ? scopeRecord.scope : scopeRecord;
122
+ }
123
+
124
+ export function getRepositoryPermissionScope(actions: Model[], names: readonly string[]): RepositoryPermissionScope {
125
+ const ids = new Set<number | string>();
126
+ let unrestricted = false;
127
+ for (const action of actions) {
128
+ const actionData = action.toJSON() as Record<string, unknown>;
129
+ if (typeof actionData.name !== 'string' || !names.includes(actionData.name)) continue;
130
+ const scope = actionScope(actionData);
131
+ const resolution = resolveRepositoryScope(scope);
132
+ if (!resolution.supported) {
133
+ return { ids: [], unrestricted: false, supported: false };
134
+ }
135
+ if (resolution.unrestricted) {
136
+ unrestricted = true;
137
+ continue;
138
+ }
139
+ resolution.ids.forEach((id) => ids.add(id));
140
+ }
141
+ return { ids: [...ids], unrestricted, supported: true };
142
+ }
143
+
144
+ export function getRepositoryPermissionIds(actions: Model[], names: readonly string[]) {
145
+ return getRepositoryPermissionScope(actions, names).ids;
146
+ }
147
+
148
+ export function repositoryPermissionIdsForDisplay(
149
+ scope: RepositoryPermissionScope,
150
+ repositoryIds: Array<number | string>,
151
+ ): Array<number | string> {
152
+ return scope.unrestricted ? repositoryIds : scope.ids;
153
+ }
154
+
155
+ export async function syncScopedActions(
156
+ db: Database,
157
+ resource: Model,
158
+ actionNames: readonly string[],
159
+ ids: Array<number | string>,
160
+ options: { unrestricted?: boolean } = {},
161
+ ) {
162
+ const rolesResourceId = getRecordValue(resource, 'id');
163
+ const actionsRepo = db.getRepository('rolesResourcesActions');
164
+ for (const storedActionName of actionNames) {
165
+ const action = await actionsRepo.findOne({
166
+ filter: { rolesResourceId, name: storedActionName },
167
+ appends: ['scope'],
168
+ });
169
+ if (action) {
170
+ if (options.unrestricted) {
171
+ await action.update({ scopeId: null });
172
+ continue;
173
+ }
174
+ const scopeJson = { $and: [{ id: { $in: ids } }] };
175
+ const actionData = action.toJSON() as Record<string, unknown>;
176
+ const actionScopeId =
177
+ getRecordValue(actionData.scope, 'id') || actionData.scopeId || getRecordValue(action, 'scopeId');
178
+ if (actionScopeId) {
179
+ await db.getRepository('rolesResourcesScopes').update({
180
+ filterByTk: actionScopeId,
181
+ values: { scope: scopeJson },
182
+ });
183
+ } else {
184
+ const newScope = await db.getRepository('rolesResourcesScopes').create({ values: { scope: scopeJson } });
185
+ await action.update({ scopeId: getRecordValue(newScope, 'id') });
186
+ }
187
+ } else {
188
+ if (options.unrestricted) {
189
+ await actionsRepo.create({
190
+ values: { rolesResourceId, name: storedActionName },
191
+ });
192
+ continue;
193
+ }
194
+ const scopeJson = { $and: [{ id: { $in: ids } }] };
195
+ const newScope = await db.getRepository('rolesResourcesScopes').create({ values: { scope: scopeJson } });
196
+ await actionsRepo.create({
197
+ values: { rolesResourceId, name: storedActionName, scopeId: getRecordValue(newScope, 'id') },
198
+ });
199
+ }
200
+ }
3
201
  }
4
202
 
5
203
  /**
@@ -27,27 +225,35 @@ export async function rolePermissions(ctx: any, _next: () => Promise<void>) {
27
225
  filter: { rolesResourceId: getRecordValue(resource, 'id') },
28
226
  appends: ['scope'],
29
227
  });
228
+ const gitManagerResource = await ctx.db.getRepository('rolesResources').findOne({
229
+ filter: { roleName, name: 'gitManager' },
230
+ });
231
+ const gitManagerActions = gitManagerResource
232
+ ? await ctx.db.getRepository('rolesResourcesActions').find({
233
+ filter: { rolesResourceId: getRecordValue(gitManagerResource, 'id') },
234
+ appends: ['scope'],
235
+ })
236
+ : [];
30
237
 
31
- const result = { read: [], write: [] };
32
- for (const action of actions) {
33
- const actionData = action.toJSON ? action.toJSON() : action;
34
- const actionName = actionData.name;
35
- if (result[actionName]) {
36
- const scopeRow = actionData.scope;
37
- const scope = scopeRow?.scope || scopeRow;
38
- try {
39
- if (scope && scope.$and && scope.$and[0] && scope.$and[0].id) {
40
- if (scope.$and[0].id.$in) {
41
- result[actionName] = scope.$and[0].id.$in;
42
- } else if (typeof scope.$and[0].id === 'number' || typeof scope.$and[0].id === 'string') {
43
- result[actionName] = [scope.$and[0].id];
44
- }
45
- }
46
- } catch (e) {
47
- // Unrecognized scope structure, skip
48
- }
49
- }
50
- }
238
+ const readScope = getRepositoryPermissionScope(actions, [...REPOSITORY_READ_ACTIONS, 'read']);
239
+ const gitWriteScope = getRepositoryPermissionScope(gitManagerActions, GIT_WRITE_ACTIONS);
240
+ const repositoryWriteScope = getRepositoryPermissionScope(actions, ['write']);
241
+ const requiresRepositoryList =
242
+ readScope.unrestricted || gitWriteScope.unrestricted || repositoryWriteScope.unrestricted;
243
+ const repositoryIds = requiresRepositoryList
244
+ ? (await ctx.db.getRepository('gitRepositories').find({ fields: ['id'] })).map((repository: Model) =>
245
+ getRecordValue(repository, 'id'),
246
+ )
247
+ : [];
248
+ const result = {
249
+ read: repositoryPermissionIdsForDisplay(readScope, repositoryIds),
250
+ write: [
251
+ ...new Set([
252
+ ...repositoryPermissionIdsForDisplay(gitWriteScope, repositoryIds),
253
+ ...repositoryPermissionIdsForDisplay(repositoryWriteScope, repositoryIds),
254
+ ]),
255
+ ],
256
+ };
51
257
  ctx.body = result;
52
258
  }
53
259
 
@@ -77,50 +283,36 @@ export async function updateRolePermissions(ctx: any, _next: () => Promise<void>
77
283
  await resource.update({ usingActionsConfig: true });
78
284
  }
79
285
 
80
- const rolesResourceId = getRecordValue(resource, 'id');
81
286
  const actionsRepo = ctx.db.getRepository('rolesResourcesActions');
82
- for (const actionName of ['read', 'write']) {
83
- const ids = permissions[actionName] || [];
84
- const action = await actionsRepo.findOne({
85
- filter: { rolesResourceId, name: actionName },
86
- appends: ['scope'],
87
- });
287
+ const readIds = permissions.read || [];
288
+ const writeIds = permissions.write || [];
289
+ const effectiveReadIds = [...new Set([...readIds, ...writeIds])];
290
+ await syncScopedActions(ctx.db, resource, REPOSITORY_READ_ACTIONS, effectiveReadIds);
88
291
 
89
- if (ids.length === 0) {
90
- // Remove the action if no ids allowed
91
- if (action) await action.destroy();
92
- } else {
93
- const scopeJson = { $and: [{ id: { $in: ids } }] };
94
- if (action) {
95
- const actionData = action.toJSON ? action.toJSON() : action;
96
- const actionScope = actionData.scope;
97
- const actionScopeId =
98
- getRecordValue(actionScope, 'id') || actionData.scopeId || getRecordValue(action, 'scopeId');
99
- if (actionScopeId) {
100
- await ctx.db.getRepository('rolesResourcesScopes').update({
101
- filterByTk: actionScopeId,
102
- values: { scope: scopeJson },
103
- });
104
- } else {
105
- const newScope = await ctx.db.getRepository('rolesResourcesScopes').create({
106
- values: { scope: scopeJson },
107
- });
108
- await action.update({ scopeId: getRecordValue(newScope, 'id') });
109
- }
110
- } else {
111
- const newScope = await ctx.db.getRepository('rolesResourcesScopes').create({
112
- values: { scope: scopeJson },
113
- });
114
- await actionsRepo.create({
115
- values: { rolesResourceId, name: actionName, scopeId: getRecordValue(newScope, 'id') },
116
- });
117
- }
118
- }
292
+ let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: 'gitManager' } });
293
+ if (!gitManagerResource) {
294
+ gitManagerResource = await resourceRepo.create({
295
+ values: { roleName, name: 'gitManager', usingActionsConfig: true },
296
+ });
297
+ } else if (!getRecordValue(gitManagerResource, 'usingActionsConfig')) {
298
+ await gitManagerResource.update({ usingActionsConfig: true });
119
299
  }
300
+ await syncScopedActions(ctx.db, gitManagerResource, GIT_READ_ACTIONS, effectiveReadIds);
301
+ await syncScopedActions(ctx.db, gitManagerResource, GIT_WRITE_ACTIONS, writeIds);
302
+
303
+ const legacyReadAction = await actionsRepo.findOne({
304
+ filter: { rolesResourceId: getRecordValue(resource, 'id'), name: 'read' },
305
+ });
306
+ if (legacyReadAction) await legacyReadAction.destroy();
307
+ const legacyWriteAction = await actionsRepo.findOne({
308
+ filter: { rolesResourceId: getRecordValue(resource, 'id'), name: 'write' },
309
+ });
310
+ if (legacyWriteAction) await legacyWriteAction.destroy();
120
311
 
121
312
  // Force reload the ACL cache in memory for this resource
122
313
  try {
123
314
  await resource.writeToACL({ acl: ctx.app.acl });
315
+ await gitManagerResource.writeToACL({ acl: ctx.app.acl });
124
316
  } catch (e) {
125
317
  ctx.logger?.warn?.('[git-manager] Failed to write resource to ACL memory cache:', e);
126
318
  }
@@ -4,6 +4,7 @@ import * as os from 'os';
4
4
  import * as path from 'path';
5
5
  import type { SimpleGit } from 'simple-git';
6
6
  import { createGit, validateBranch, validateLocalPath, withAuth } from './git-actions';
7
+ import { getEffectiveActionParams } from '../repository-access';
7
8
  import { getRepoAccount } from '../utils/get-repo-account';
8
9
  import { redactError, redactPat } from '../utils/redact';
9
10
 
@@ -43,11 +44,6 @@ interface RunParams {
43
44
  expectedTargetSha?: string;
44
45
  }
45
46
 
46
- function getActionParams(ctx: Context): Record<string, unknown> {
47
- const requestBody = (ctx as Context & { request?: { body?: Record<string, unknown> } }).request?.body || {};
48
- return { ...ctx.action.params, ...ctx.action.params?.values, ...requestBody };
49
- }
50
-
51
47
  function stringValue(value: unknown, fallback = ''): string {
52
48
  return typeof value === 'string' ? value.trim() : fallback;
53
49
  }
@@ -320,7 +316,7 @@ async function loadConfigAndRepository(ctx: Context, configId: number | string)
320
316
  }
321
317
 
322
318
  export async function subtreeOptions(ctx: Context, next: () => Promise<void>) {
323
- const params = getActionParams(ctx);
319
+ const params = getEffectiveActionParams(ctx);
324
320
  const repositoryId = params.repositoryId as number | string;
325
321
  if (!repositoryId) ctx.throw(400, 'repositoryId is required');
326
322
  const remoteName = validateRemoteName(stringValue(params.remoteName, 'origin') || 'origin');
@@ -379,7 +375,7 @@ export async function subtreeOptions(ctx: Context, next: () => Promise<void>) {
379
375
  }
380
376
 
381
377
  export async function subtreePreview(ctx: Context, next: () => Promise<void>) {
382
- const params = getActionParams(ctx);
378
+ const params = getEffectiveActionParams(ctx);
383
379
  const configId = params.configId as number | string;
384
380
  if (!configId) ctx.throw(400, 'configId is required');
385
381
  const { config, repo, account } = await loadConfigAndRepository(ctx, configId);
@@ -410,7 +406,7 @@ export async function subtreePreview(ctx: Context, next: () => Promise<void>) {
410
406
  * This action intentionally does not enqueue work in the automatic-review queue.
411
407
  */
412
408
  export async function subtreeRunOnAppProcess(ctx: Context, next: () => Promise<void>) {
413
- const params = getActionParams(ctx);
409
+ const params = getEffectiveActionParams(ctx);
414
410
  const runParams: RunParams = {
415
411
  configId: params.configId as number | string,
416
412
  policy: validateSubtreePolicy(params.policy),
@@ -0,0 +1,81 @@
1
+ import { Migration } from '@nocobase/server';
2
+ import type { Model } from '@nocobase/database';
3
+
4
+ import {
5
+ GIT_READ_ACTIONS,
6
+ GIT_WRITE_ACTIONS,
7
+ REPOSITORY_READ_ACTIONS,
8
+ getRepositoryPermissionScope,
9
+ syncScopedActions,
10
+ } from '../actions/role-permissions';
11
+
12
+ function getRecordValue(record: unknown, key: string) {
13
+ if (!record || typeof record !== 'object') return undefined;
14
+ const model = record as { get?: (attribute: string) => unknown } & Record<string, unknown>;
15
+ return typeof model.get === 'function' ? model.get(key) : model[key];
16
+ }
17
+
18
+ export default class MigrateLegacyRepositoryPermissions extends Migration {
19
+ on = 'afterLoad';
20
+
21
+ async up() {
22
+ const resourceRepo = this.db.getRepository('rolesResources');
23
+ const actionsRepo = this.db.getRepository('rolesResourcesActions');
24
+ const repositoryResources = await resourceRepo.find({ filter: { name: 'gitRepositories' } });
25
+
26
+ for (const repositoryResource of repositoryResources) {
27
+ const rolesResourceId = getRecordValue(repositoryResource, 'id');
28
+ const roleName = getRecordValue(repositoryResource, 'roleName');
29
+ if (!rolesResourceId || !roleName) continue;
30
+
31
+ const actions = await actionsRepo.find({
32
+ filter: { rolesResourceId },
33
+ appends: ['scope'],
34
+ });
35
+ const legacyRead = actions.filter((action) => getRecordValue(action, 'name') === 'read') as Model[];
36
+ const legacyWrite = actions.filter((action) => getRecordValue(action, 'name') === 'write') as Model[];
37
+ if (legacyRead.length === 0 && legacyWrite.length === 0) continue;
38
+
39
+ const readPermission = getRepositoryPermissionScope(legacyRead, ['read']);
40
+ const writePermission = getRepositoryPermissionScope(legacyWrite, ['write']);
41
+ if (!readPermission.supported || !writePermission.supported) {
42
+ this.app.log?.warn(
43
+ `[git-manager] skipped repository permission migration for role ${String(
44
+ roleName,
45
+ )} because its legacy scope cannot be represented safely`,
46
+ );
47
+ continue;
48
+ }
49
+ const effectiveReadIds = [...new Set([...readPermission.ids, ...writePermission.ids])];
50
+ const effectiveReadUnrestricted = readPermission.unrestricted || writePermission.unrestricted;
51
+ if (effectiveReadIds.length === 0 && !effectiveReadUnrestricted && !writePermission.unrestricted) continue;
52
+
53
+ await syncScopedActions(this.db, repositoryResource, REPOSITORY_READ_ACTIONS, effectiveReadIds, {
54
+ unrestricted: effectiveReadUnrestricted,
55
+ });
56
+
57
+ let gitManagerResource = await resourceRepo.findOne({ filter: { roleName, name: 'gitManager' } });
58
+ if (!gitManagerResource) {
59
+ gitManagerResource = await resourceRepo.create({
60
+ values: { roleName, name: 'gitManager', usingActionsConfig: true },
61
+ });
62
+ } else if (!getRecordValue(gitManagerResource, 'usingActionsConfig')) {
63
+ await gitManagerResource.update({ usingActionsConfig: true });
64
+ }
65
+
66
+ await syncScopedActions(this.db, gitManagerResource, GIT_READ_ACTIONS, effectiveReadIds, {
67
+ unrestricted: effectiveReadUnrestricted,
68
+ });
69
+ await syncScopedActions(this.db, gitManagerResource, GIT_WRITE_ACTIONS, writePermission.ids, {
70
+ unrestricted: writePermission.unrestricted,
71
+ });
72
+
73
+ for (const action of [...legacyRead, ...legacyWrite]) {
74
+ await action.destroy();
75
+ }
76
+
77
+ await repositoryResource.writeToACL({ acl: this.app.acl });
78
+ await gitManagerResource.writeToACL({ acl: this.app.acl });
79
+ }
80
+ }
81
+ }
@@ -11,17 +11,40 @@ import * as subtreeActions from './actions/subtree';
11
11
  import { recoverStuckReviews, registerReviewQueue, unregisterReviewQueue } from './actions/review';
12
12
  import { registerGitReviewAiTools } from './ai-tools';
13
13
  import { startPoller, stopPoller } from './poller';
14
- import { RegistryGitContentService } from './services/registry-content-service';
14
+ import { RegistryGitContentService, SkillHubGitContentService } from './services/registry-content-service';
15
+ import { enforceRepositoryAccess, enforceRepositoryCollectionAccess } from './repository-access';
16
+ import { isGitManagerResourceResponse, redactCredentialFields } from './utils/redact';
17
+ import { containsCredentialBearingUrlField, URL_USERINFO_NOT_ALLOWED } from './utils/url-security';
18
+
19
+ const GIT_CONFIGURATION_URL_FIELDS = new Set(['repoUrl', 'baseUrl']);
20
+
21
+ export function isGitConfigurationUrlMutation(resourceName: unknown, actionName: unknown): boolean {
22
+ return (
23
+ typeof actionName === 'string' &&
24
+ ['create', 'update'].includes(actionName) &&
25
+ isGitManagerResourceResponse(resourceName)
26
+ );
27
+ }
15
28
 
16
29
  export class PluginGitManagerServer extends Plugin {
17
30
  // @ts-ignore
18
31
  declare app: any;
19
32
  // @ts-ignore
20
33
  declare db: any;
21
- registryContentService: RegistryGitContentService;
34
+ registryContentService!: RegistryGitContentService;
35
+ skillHubContentService!: SkillHubGitContentService;
22
36
 
23
37
  async afterAdd() {
24
- this.registryContentService = new RegistryGitContentService((this as unknown as { db: Database }).db);
38
+ this.registryContentService = new RegistryGitContentService(
39
+ (this as unknown as { db: Database }).db,
40
+ undefined,
41
+ this.app.acl,
42
+ );
43
+ this.skillHubContentService = new SkillHubGitContentService(
44
+ (this as unknown as { db: Database }).db,
45
+ undefined,
46
+ this.app.acl,
47
+ );
25
48
  }
26
49
 
27
50
  async beforeLoad() {
@@ -76,6 +99,9 @@ export class PluginGitManagerServer extends Plugin {
76
99
  },
77
100
  });
78
101
 
102
+ (this as any).app.resourceManager.use(enforceRepositoryAccess);
103
+ (this as any).app.resourceManager.use(enforceRepositoryCollectionAccess);
104
+
79
105
  // Suppress noisy workflow pre-action/post-action warnings for custom resources
80
106
  (this as any).app.use(async (ctx, next) => {
81
107
  if (ctx.logger && ctx.logger.warn) {
@@ -251,10 +277,22 @@ export class PluginGitManagerServer extends Plugin {
251
277
  }
252
278
  }
253
279
 
254
- if (
255
- (resource === 'gitRepositories' || resource === 'gitAccounts') &&
256
- ['create', 'update'].includes(ctx.action?.actionName)
257
- ) {
280
+ if (isGitConfigurationUrlMutation(resource, ctx.action?.actionName)) {
281
+ const actionParams = ctx.action?.params;
282
+ const requestBody = ctx.request?.body;
283
+ const hasCredentialBearingUrl = [
284
+ actionParams,
285
+ actionParams?.values,
286
+ requestBody,
287
+ requestBody?.values,
288
+ ctx.query,
289
+ ctx.request?.query,
290
+ ].some((source) => containsCredentialBearingUrlField(source, GIT_CONFIGURATION_URL_FIELDS));
291
+
292
+ if (hasCredentialBearingUrl) {
293
+ ctx.throw(400, ctx.t(URL_USERINFO_NOT_ALLOWED, { ns: (this as any).name }));
294
+ }
295
+
258
296
  if (ctx.action.params?.values?.pat === '••••••••') {
259
297
  delete ctx.action.params.values.pat;
260
298
  }
@@ -265,28 +303,14 @@ export class PluginGitManagerServer extends Plugin {
265
303
  return next();
266
304
  });
267
305
 
268
- // Strip PAT from API responses — scoped to gitRepositories and gitAccounts
306
+ // Strip PAT from every Git Manager response, including nested association routes.
269
307
  (this as any).app.resourceManager.use(async (ctx, next) => {
270
308
  const resource = ctx.action?.resourceName;
271
- if (resource !== 'gitRepositories' && resource !== 'gitAccounts') {
309
+ if (!isGitManagerResourceResponse(resource)) {
272
310
  return next();
273
311
  }
274
312
  await next();
275
- if (ctx.body) {
276
- const items = Array.isArray(ctx.body)
277
- ? ctx.body
278
- : ctx.body?.data
279
- ? Array.isArray(ctx.body.data)
280
- ? ctx.body.data
281
- : [ctx.body.data]
282
- : [ctx.body];
283
- items.forEach((item) => {
284
- if (item && typeof item === 'object') {
285
- if (item.pat) item.pat = '••••••••';
286
- if (item.dataValues?.pat) item.dataValues.pat = '••••••••';
287
- }
288
- });
289
- }
313
+ redactCredentialFields(ctx.body);
290
314
  });
291
315
  }
292
316