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.
- package/dist/client/{434.1d19d4d6acc114f1.js → 434.b2eeaaef33aae6e0.js} +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/{434.f8836ea116648de1.js → 434.7a27051db18526c0.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- 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 +217 -54
- package/dist/server/actions/subtree.js +4 -8
- package/dist/server/migrations/20260730000000-migrate-legacy-repository-permissions.js +94 -0
- package/dist/server/plugin.js +44 -19
- package/dist/server/repository-access.js +570 -0
- 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/client/components/RepositoryConfig.tsx +4 -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 +752 -0
- package/src/server/__tests__/review.test.ts +137 -0
- package/src/server/__tests__/role-permissions.test.ts +147 -0
- 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 +251 -59
- package/src/server/actions/subtree.ts +4 -8
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -0
- package/src/server/plugin.ts +48 -24
- package/src/server/repository-access.ts +773 -0
- 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
|
@@ -28,16 +28,26 @@ var registry_content_service_exports = {};
|
|
|
28
28
|
__export(registry_content_service_exports, {
|
|
29
29
|
REGISTRY_CONTENT_LIMIT_EXCEEDED: () => REGISTRY_CONTENT_LIMIT_EXCEEDED,
|
|
30
30
|
REGISTRY_EXPORT_NOT_GRANTED: () => REGISTRY_EXPORT_NOT_GRANTED,
|
|
31
|
+
REGISTRY_GIT_CONTENT_CAPABILITIES: () => REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
32
|
+
REGISTRY_GIT_CONTENT_CONTRACT_VERSION: () => REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
31
33
|
REGISTRY_GIT_FILE_NOT_FOUND: () => REGISTRY_GIT_FILE_NOT_FOUND,
|
|
34
|
+
REGISTRY_REPOSITORY_ACCESS_DENIED: () => REGISTRY_REPOSITORY_ACCESS_DENIED,
|
|
32
35
|
RegistryContentLimitError: () => RegistryContentLimitError,
|
|
33
36
|
RegistryExportNotGrantedError: () => RegistryExportNotGrantedError,
|
|
34
37
|
RegistryGitContentService: () => RegistryGitContentService,
|
|
35
|
-
RegistryGitFileNotFoundError: () => RegistryGitFileNotFoundError
|
|
38
|
+
RegistryGitFileNotFoundError: () => RegistryGitFileNotFoundError,
|
|
39
|
+
RegistryRepositoryAccessDeniedError: () => RegistryRepositoryAccessDeniedError,
|
|
40
|
+
SKILL_HUB_GIT_CONTENT_CAPABILITIES: () => SKILL_HUB_GIT_CONTENT_CAPABILITIES,
|
|
41
|
+
SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION: () => SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION,
|
|
42
|
+
SKILL_HUB_REPOSITORY_ACCESS_DENIED: () => SKILL_HUB_REPOSITORY_ACCESS_DENIED,
|
|
43
|
+
SkillHubGitContentService: () => SkillHubGitContentService,
|
|
44
|
+
SkillHubRepositoryAccessDeniedError: () => SkillHubRepositoryAccessDeniedError
|
|
36
45
|
});
|
|
37
46
|
module.exports = __toCommonJS(registry_content_service_exports);
|
|
38
47
|
var import_child_process = require("child_process");
|
|
39
48
|
var import_fs = require("fs");
|
|
40
49
|
var import_git_actions = require("../actions/git-actions");
|
|
50
|
+
var import_repository_access = require("../repository-access");
|
|
41
51
|
function positiveLimit(value, fallback, maximum) {
|
|
42
52
|
const parsed = Number(value);
|
|
43
53
|
return Number.isSafeInteger(parsed) && parsed > 0 && parsed <= maximum ? parsed : fallback;
|
|
@@ -52,8 +62,17 @@ const DEFAULT_REGISTRY_GIT_CONTENT_LIMITS = Object.freeze({
|
|
|
52
62
|
)
|
|
53
63
|
});
|
|
54
64
|
const REGISTRY_EXPORT_NOT_GRANTED = "REGISTRY_EXPORT_NOT_GRANTED";
|
|
65
|
+
const REGISTRY_REPOSITORY_ACCESS_DENIED = "REGISTRY_REPOSITORY_ACCESS_DENIED";
|
|
66
|
+
const SKILL_HUB_REPOSITORY_ACCESS_DENIED = "SKILL_HUB_REPOSITORY_ACCESS_DENIED";
|
|
55
67
|
const REGISTRY_CONTENT_LIMIT_EXCEEDED = "REGISTRY_CONTENT_LIMIT_EXCEEDED";
|
|
56
68
|
const REGISTRY_GIT_FILE_NOT_FOUND = "REGISTRY_GIT_FILE_NOT_FOUND";
|
|
69
|
+
const REGISTRY_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
70
|
+
const REGISTRY_GIT_CONTENT_CAPABILITIES = [
|
|
71
|
+
"registry-content-with-actor",
|
|
72
|
+
"registry-content-authorize-source"
|
|
73
|
+
];
|
|
74
|
+
const SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
75
|
+
const SKILL_HUB_GIT_CONTENT_CAPABILITIES = ["skill-hub-content-with-actor"];
|
|
57
76
|
const DEFAULT_GIT_TIMEOUT_MS = 3e4;
|
|
58
77
|
const MAX_STDERR_BYTES = 64 * 1024;
|
|
59
78
|
class RegistryExportNotGrantedError extends Error {
|
|
@@ -63,6 +82,20 @@ class RegistryExportNotGrantedError extends Error {
|
|
|
63
82
|
this.name = "RegistryExportNotGrantedError";
|
|
64
83
|
}
|
|
65
84
|
}
|
|
85
|
+
class RegistryRepositoryAccessDeniedError extends Error {
|
|
86
|
+
code = REGISTRY_REPOSITORY_ACCESS_DENIED;
|
|
87
|
+
constructor() {
|
|
88
|
+
super("The current actor is not authorized to read this repository for registry export.");
|
|
89
|
+
this.name = "RegistryRepositoryAccessDeniedError";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
class SkillHubRepositoryAccessDeniedError extends Error {
|
|
93
|
+
code = SKILL_HUB_REPOSITORY_ACCESS_DENIED;
|
|
94
|
+
constructor() {
|
|
95
|
+
super("The current actor is not authorized to read this repository for Skill Hub.");
|
|
96
|
+
this.name = "SkillHubRepositoryAccessDeniedError";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
66
99
|
class RegistryContentLimitError extends Error {
|
|
67
100
|
code = REGISTRY_CONTENT_LIMIT_EXCEEDED;
|
|
68
101
|
constructor(message) {
|
|
@@ -77,6 +110,22 @@ class RegistryGitFileNotFoundError extends Error {
|
|
|
77
110
|
this.name = "RegistryGitFileNotFoundError";
|
|
78
111
|
}
|
|
79
112
|
}
|
|
113
|
+
const REGISTRY_CONTENT_ACCESS_POLICY = {
|
|
114
|
+
contractVersion: REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
115
|
+
capabilities: REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
116
|
+
allowsSystemScheduledSync: true,
|
|
117
|
+
requiresRegistryExport: true,
|
|
118
|
+
createAccessDeniedError: () => new RegistryRepositoryAccessDeniedError(),
|
|
119
|
+
createRepositoryUnavailableError: () => new RegistryExportNotGrantedError()
|
|
120
|
+
};
|
|
121
|
+
const SKILL_HUB_CONTENT_ACCESS_POLICY = {
|
|
122
|
+
contractVersion: SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION,
|
|
123
|
+
capabilities: SKILL_HUB_GIT_CONTENT_CAPABILITIES,
|
|
124
|
+
allowsSystemScheduledSync: false,
|
|
125
|
+
requiresRegistryExport: false,
|
|
126
|
+
createAccessDeniedError: () => new SkillHubRepositoryAccessDeniedError(),
|
|
127
|
+
createRepositoryUnavailableError: () => new SkillHubRepositoryAccessDeniedError()
|
|
128
|
+
};
|
|
80
129
|
function boundedPositive(value, fallback, maximum) {
|
|
81
130
|
return Number.isSafeInteger(value) && Number(value) > 0 && Number(value) <= maximum ? Number(value) : fallback;
|
|
82
131
|
}
|
|
@@ -88,17 +137,17 @@ function runGitBuffer(localPath, args, maximumBytes, timeoutMs) {
|
|
|
88
137
|
let stderr = "";
|
|
89
138
|
let stderrBytes = 0;
|
|
90
139
|
let settled = false;
|
|
91
|
-
|
|
92
|
-
|
|
140
|
+
let pendingFailure;
|
|
141
|
+
const stop = (error) => {
|
|
142
|
+
if (settled || pendingFailure) {
|
|
93
143
|
return;
|
|
94
144
|
}
|
|
95
|
-
|
|
145
|
+
pendingFailure = error;
|
|
96
146
|
clearTimeout(timer);
|
|
97
147
|
child.kill();
|
|
98
|
-
reject(error);
|
|
99
148
|
};
|
|
100
149
|
const timer = setTimeout(() => {
|
|
101
|
-
|
|
150
|
+
stop(new RegistryContentLimitError("Git registry read exceeded its execution timeout."));
|
|
102
151
|
}, timeoutMs);
|
|
103
152
|
child.stdout.on("data", (chunk) => {
|
|
104
153
|
if (settled) {
|
|
@@ -106,7 +155,7 @@ function runGitBuffer(localPath, args, maximumBytes, timeoutMs) {
|
|
|
106
155
|
}
|
|
107
156
|
outputBytes += chunk.length;
|
|
108
157
|
if (outputBytes > maximumBytes) {
|
|
109
|
-
|
|
158
|
+
stop(new RegistryContentLimitError("Git registry read exceeded its output limit."));
|
|
110
159
|
return;
|
|
111
160
|
}
|
|
112
161
|
chunks.push(chunk);
|
|
@@ -120,13 +169,22 @@ function runGitBuffer(localPath, args, maximumBytes, timeoutMs) {
|
|
|
120
169
|
stderrBytes += bounded.length;
|
|
121
170
|
stderr += bounded.toString("utf8");
|
|
122
171
|
});
|
|
123
|
-
child.once("error", (error) =>
|
|
172
|
+
child.once("error", (error) => {
|
|
173
|
+
if (!pendingFailure) {
|
|
174
|
+
pendingFailure = error;
|
|
175
|
+
clearTimeout(timer);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
124
178
|
child.once("close", (code) => {
|
|
125
179
|
if (settled) {
|
|
126
180
|
return;
|
|
127
181
|
}
|
|
128
182
|
settled = true;
|
|
129
183
|
clearTimeout(timer);
|
|
184
|
+
if (pendingFailure) {
|
|
185
|
+
reject(pendingFailure);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
130
188
|
if (code !== 0) {
|
|
131
189
|
if (/does not exist in|exists on disk, but not in|path .* does not exist/i.test(stderr)) {
|
|
132
190
|
reject(new RegistryGitFileNotFoundError());
|
|
@@ -174,13 +232,27 @@ function parseTreeLine(line, rootPath) {
|
|
|
174
232
|
size: match[4] === "-" ? 0 : Number.parseInt(match[4], 10)
|
|
175
233
|
};
|
|
176
234
|
}
|
|
177
|
-
class
|
|
178
|
-
constructor(database, limits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS) {
|
|
235
|
+
class GitContentService {
|
|
236
|
+
constructor(database, limits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS, acl, accessPolicy = REGISTRY_CONTENT_ACCESS_POLICY) {
|
|
179
237
|
this.database = database;
|
|
180
238
|
this.limits = limits;
|
|
239
|
+
this.acl = acl;
|
|
240
|
+
this.accessPolicy = accessPolicy;
|
|
241
|
+
this.contractVersion = accessPolicy.contractVersion;
|
|
242
|
+
this.capabilities = accessPolicy.capabilities;
|
|
181
243
|
}
|
|
182
|
-
|
|
183
|
-
|
|
244
|
+
contractVersion;
|
|
245
|
+
capabilities;
|
|
246
|
+
/**
|
|
247
|
+
* Validates actor access before a cross-plugin service binds or reads a
|
|
248
|
+
* repository. The concrete service policy decides whether Registry export
|
|
249
|
+
* opt-in or scheduled system access is permitted.
|
|
250
|
+
*/
|
|
251
|
+
async assertRepositoryAccess(repositoryId, access) {
|
|
252
|
+
await this.findRepository(repositoryId, access);
|
|
253
|
+
}
|
|
254
|
+
async resolveCommit(repositoryId, ref, access) {
|
|
255
|
+
const repository = await this.findRepository(repositoryId, access);
|
|
184
256
|
const localPath = (0, import_git_actions.validateLocalPath)(repositoryValue(repository, "localPath"));
|
|
185
257
|
if (!(0, import_fs.existsSync)(localPath)) {
|
|
186
258
|
throw new Error("Repository directory does not exist. Clone the repository before reading its content.");
|
|
@@ -196,8 +268,8 @@ class RegistryGitContentService {
|
|
|
196
268
|
}
|
|
197
269
|
return result.toLowerCase();
|
|
198
270
|
}
|
|
199
|
-
async listTree(input) {
|
|
200
|
-
const repository = await this.findRepository(input.repositoryId);
|
|
271
|
+
async listTree(input, access) {
|
|
272
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
201
273
|
const localPath = (0, import_git_actions.validateLocalPath)(repositoryValue(repository, "localPath"));
|
|
202
274
|
if (!(0, import_fs.existsSync)(localPath)) {
|
|
203
275
|
throw new Error("Repository directory does not exist. Clone the repository before reading its content.");
|
|
@@ -217,8 +289,8 @@ class RegistryGitContentService {
|
|
|
217
289
|
}
|
|
218
290
|
return lines.map((line) => parseTreeLine(line, rootPath)).filter((entry) => entry !== null).sort((left, right) => left.path.localeCompare(right.path));
|
|
219
291
|
}
|
|
220
|
-
async readFile(input) {
|
|
221
|
-
const repository = await this.findRepository(input.repositoryId);
|
|
292
|
+
async readFile(input, access) {
|
|
293
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
222
294
|
const localPath = (0, import_git_actions.validateLocalPath)(repositoryValue(repository, "localPath"));
|
|
223
295
|
if (!(0, import_fs.existsSync)(localPath)) {
|
|
224
296
|
throw new Error("Repository directory does not exist. Clone the repository before reading its content.");
|
|
@@ -235,8 +307,8 @@ class RegistryGitContentService {
|
|
|
235
307
|
throw error;
|
|
236
308
|
}
|
|
237
309
|
}
|
|
238
|
-
async archiveTree(input) {
|
|
239
|
-
const repository = await this.findRepository(input.repositoryId);
|
|
310
|
+
async archiveTree(input, access) {
|
|
311
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
240
312
|
const localPath = (0, import_git_actions.validateLocalPath)(repositoryValue(repository, "localPath"));
|
|
241
313
|
if (!(0, import_fs.existsSync)(localPath)) {
|
|
242
314
|
throw new Error("Repository directory does not exist. Clone the repository before reading its content.");
|
|
@@ -265,17 +337,41 @@ class RegistryGitContentService {
|
|
|
265
337
|
});
|
|
266
338
|
});
|
|
267
339
|
}
|
|
268
|
-
async findRepository(repositoryId) {
|
|
340
|
+
async findRepository(repositoryId, access) {
|
|
341
|
+
await this.assertAccess(repositoryId, access);
|
|
269
342
|
const repository = await this.database.getRepository("gitRepositories").findOne({ filterByTk: repositoryId });
|
|
270
343
|
if (!repository) {
|
|
271
|
-
throw
|
|
344
|
+
throw this.accessPolicy.createRepositoryUnavailableError();
|
|
272
345
|
}
|
|
273
346
|
const repositoryModel = repository;
|
|
274
|
-
if (repositoryModel.get("registryExportEnabled") !== true) {
|
|
347
|
+
if (this.accessPolicy.requiresRegistryExport && repositoryModel.get("registryExportEnabled") !== true) {
|
|
275
348
|
throw new RegistryExportNotGrantedError();
|
|
276
349
|
}
|
|
277
350
|
return repositoryModel;
|
|
278
351
|
}
|
|
352
|
+
async assertAccess(repositoryId, access) {
|
|
353
|
+
if (!access) {
|
|
354
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
355
|
+
}
|
|
356
|
+
if (access.kind === "system") {
|
|
357
|
+
if (this.accessPolicy.allowsSystemScheduledSync && access.reason === "scheduled-sync") {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
361
|
+
}
|
|
362
|
+
if (access.kind !== "user" || !Array.isArray(access.roles) || !access.roles.every((role) => typeof role === "string")) {
|
|
363
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
364
|
+
}
|
|
365
|
+
const allowed = await (0, import_repository_access.hasRepositoryAccess)({
|
|
366
|
+
acl: this.acl,
|
|
367
|
+
roles: access.roles,
|
|
368
|
+
repositoryId,
|
|
369
|
+
action: "fileContent"
|
|
370
|
+
});
|
|
371
|
+
if (!allowed) {
|
|
372
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
279
375
|
assertCommitSha(value) {
|
|
280
376
|
const normalized = (0, import_git_actions.validateRef)(value);
|
|
281
377
|
if (!/^[a-f0-9]{40,64}$/i.test(normalized)) {
|
|
@@ -284,13 +380,32 @@ class RegistryGitContentService {
|
|
|
284
380
|
return normalized.toLowerCase();
|
|
285
381
|
}
|
|
286
382
|
}
|
|
383
|
+
class RegistryGitContentService extends GitContentService {
|
|
384
|
+
constructor(database, limits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS, acl) {
|
|
385
|
+
super(database, limits, acl, REGISTRY_CONTENT_ACCESS_POLICY);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
class SkillHubGitContentService extends GitContentService {
|
|
389
|
+
constructor(database, limits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS, acl) {
|
|
390
|
+
super(database, limits, acl, SKILL_HUB_CONTENT_ACCESS_POLICY);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
287
393
|
// Annotate the CommonJS export names for ESM import in node:
|
|
288
394
|
0 && (module.exports = {
|
|
289
395
|
REGISTRY_CONTENT_LIMIT_EXCEEDED,
|
|
290
396
|
REGISTRY_EXPORT_NOT_GRANTED,
|
|
397
|
+
REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
398
|
+
REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
291
399
|
REGISTRY_GIT_FILE_NOT_FOUND,
|
|
400
|
+
REGISTRY_REPOSITORY_ACCESS_DENIED,
|
|
292
401
|
RegistryContentLimitError,
|
|
293
402
|
RegistryExportNotGrantedError,
|
|
294
403
|
RegistryGitContentService,
|
|
295
|
-
RegistryGitFileNotFoundError
|
|
404
|
+
RegistryGitFileNotFoundError,
|
|
405
|
+
RegistryRepositoryAccessDeniedError,
|
|
406
|
+
SKILL_HUB_GIT_CONTENT_CAPABILITIES,
|
|
407
|
+
SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION,
|
|
408
|
+
SKILL_HUB_REPOSITORY_ACCESS_DENIED,
|
|
409
|
+
SkillHubGitContentService,
|
|
410
|
+
SkillHubRepositoryAccessDeniedError
|
|
296
411
|
});
|
|
@@ -29,17 +29,20 @@ __export(get_repo_account_exports, {
|
|
|
29
29
|
getRepoAccount: () => getRepoAccount
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(get_repo_account_exports);
|
|
32
|
+
var import_url_security = require("./url-security");
|
|
32
33
|
async function getRepoAccount(db, repo) {
|
|
33
34
|
const gitAccountId = repo.get("gitAccountId");
|
|
34
|
-
if (
|
|
35
|
+
if (typeof gitAccountId !== "number" && typeof gitAccountId !== "string") return null;
|
|
35
36
|
const account = await db.getRepository("gitAccounts").findOne({
|
|
36
37
|
filterByTk: gitAccountId
|
|
37
38
|
});
|
|
38
39
|
if (!account) return null;
|
|
40
|
+
const baseUrl = (account.get("baseUrl") || "").trim() || null;
|
|
41
|
+
if (baseUrl) (0, import_url_security.assertUrlHasNoUserInfo)(baseUrl);
|
|
39
42
|
return {
|
|
40
43
|
pat: (account.get("pat") || "").trim(),
|
|
41
44
|
username: (account.get("username") || "").trim(),
|
|
42
|
-
baseUrl
|
|
45
|
+
baseUrl,
|
|
43
46
|
provider: (account.get("provider") || "gitlab").trim()
|
|
44
47
|
};
|
|
45
48
|
}
|
|
@@ -29,7 +29,9 @@ __export(gitlab_url_exports, {
|
|
|
29
29
|
parseGitLabProject: () => parseGitLabProject
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(gitlab_url_exports);
|
|
32
|
+
var import_url_security = require("./url-security");
|
|
32
33
|
function parseGitLabProject(repoUrl) {
|
|
34
|
+
(0, import_url_security.assertUrlHasNoUserInfo)(repoUrl);
|
|
33
35
|
const url = new URL(repoUrl);
|
|
34
36
|
const projectPath = url.pathname.replace(/\.git$/, "").replace(/^\//, "");
|
|
35
37
|
if (!projectPath) {
|
|
@@ -26,24 +26,70 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
26
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
27
|
var redact_exports = {};
|
|
28
28
|
__export(redact_exports, {
|
|
29
|
+
REDACTED_PAT: () => REDACTED_PAT,
|
|
30
|
+
isGitManagerResourceResponse: () => isGitManagerResourceResponse,
|
|
31
|
+
redactCredentialFields: () => redactCredentialFields,
|
|
29
32
|
redactError: () => redactError,
|
|
30
33
|
redactPat: () => redactPat
|
|
31
34
|
});
|
|
32
35
|
module.exports = __toCommonJS(redact_exports);
|
|
36
|
+
var import_url_security = require("./url-security");
|
|
37
|
+
const REDACTED_PAT = "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
|
|
38
|
+
const GIT_MANAGER_RESOURCE_SEGMENTS = /* @__PURE__ */ new Set([
|
|
39
|
+
"gitManager",
|
|
40
|
+
"gitRepositories",
|
|
41
|
+
"gitAccounts",
|
|
42
|
+
"gitReviewFlows",
|
|
43
|
+
"gitCodeReviews",
|
|
44
|
+
"gitSubtreeConfigs",
|
|
45
|
+
"gitSubtreeRuns"
|
|
46
|
+
]);
|
|
47
|
+
function isGitManagerResourceResponse(resourceName) {
|
|
48
|
+
return typeof resourceName === "string" && resourceName.split(/[.[\],:/()=\s]+/).some((segment) => GIT_MANAGER_RESOURCE_SEGMENTS.has(segment));
|
|
49
|
+
}
|
|
33
50
|
function redactPat(s) {
|
|
34
51
|
if (typeof s !== "string") return s == null ? "" : String(s);
|
|
35
|
-
return
|
|
52
|
+
return (0, import_url_security.redactUrlUserInfo)(s);
|
|
36
53
|
}
|
|
37
54
|
function redactError(err) {
|
|
38
55
|
if (!err || typeof err !== "object") return err;
|
|
39
|
-
const
|
|
40
|
-
if (typeof
|
|
41
|
-
if (typeof
|
|
42
|
-
if (typeof
|
|
56
|
+
const error = err;
|
|
57
|
+
if (typeof error.message === "string") error.message = redactPat(error.message);
|
|
58
|
+
if (typeof error.stderr === "string") error.stderr = redactPat(error.stderr);
|
|
59
|
+
if (typeof error.stdout === "string") error.stdout = redactPat(error.stdout);
|
|
43
60
|
return err;
|
|
44
61
|
}
|
|
62
|
+
function redactCredentialFields(value) {
|
|
63
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
64
|
+
const visit = (current) => {
|
|
65
|
+
if (!current || typeof current !== "object" || visited.has(current)) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
visited.add(current);
|
|
69
|
+
if (Array.isArray(current)) {
|
|
70
|
+
current.forEach(visit);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const record = current;
|
|
74
|
+
for (const [key, nestedValue] of Object.entries(record)) {
|
|
75
|
+
if (key === "pat") {
|
|
76
|
+
record[key] = REDACTED_PAT;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if ((key === "repoUrl" || key === "baseUrl") && typeof nestedValue === "string") {
|
|
80
|
+
record[key] = (0, import_url_security.redactUrlUserInfo)(nestedValue);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
visit(nestedValue);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
visit(value);
|
|
87
|
+
}
|
|
45
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
46
89
|
0 && (module.exports = {
|
|
90
|
+
REDACTED_PAT,
|
|
91
|
+
isGitManagerResourceResponse,
|
|
92
|
+
redactCredentialFields,
|
|
47
93
|
redactError,
|
|
48
94
|
redactPat
|
|
49
95
|
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var url_security_exports = {};
|
|
28
|
+
__export(url_security_exports, {
|
|
29
|
+
URL_USERINFO_NOT_ALLOWED: () => URL_USERINFO_NOT_ALLOWED,
|
|
30
|
+
assertUrlHasNoUserInfo: () => assertUrlHasNoUserInfo,
|
|
31
|
+
containsCredentialBearingUrlField: () => containsCredentialBearingUrlField,
|
|
32
|
+
hasUrlUserInfo: () => hasUrlUserInfo,
|
|
33
|
+
redactUrlUserInfo: () => redactUrlUserInfo
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(url_security_exports);
|
|
36
|
+
const URL_USERINFO_NOT_ALLOWED = "Credential-bearing URLs are not allowed";
|
|
37
|
+
function pathSegments(value) {
|
|
38
|
+
return value.split(/[.[\],:/()=\s'"]+/);
|
|
39
|
+
}
|
|
40
|
+
function parseStructuredValue(value) {
|
|
41
|
+
const trimmed = value.trim();
|
|
42
|
+
if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(trimmed);
|
|
47
|
+
} catch {
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function hasUrlUserInfo(value) {
|
|
52
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const url = new URL(value.trim());
|
|
57
|
+
return Boolean(url.username || url.password);
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function assertUrlHasNoUserInfo(value) {
|
|
63
|
+
if (hasUrlUserInfo(value)) {
|
|
64
|
+
throw new Error(URL_USERINFO_NOT_ALLOWED);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function containsUrlUserInfo(value, visited = /* @__PURE__ */ new WeakSet()) {
|
|
68
|
+
if (typeof value === "string") {
|
|
69
|
+
return hasUrlUserInfo(value);
|
|
70
|
+
}
|
|
71
|
+
if (!value || typeof value !== "object" || visited.has(value)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
visited.add(value);
|
|
75
|
+
if (Array.isArray(value)) {
|
|
76
|
+
return value.some((item) => containsUrlUserInfo(item, visited));
|
|
77
|
+
}
|
|
78
|
+
return Object.values(value).some((item) => containsUrlUserInfo(item, visited));
|
|
79
|
+
}
|
|
80
|
+
function containsCredentialBearingUrlField(value, fieldNames, visited = /* @__PURE__ */ new WeakSet()) {
|
|
81
|
+
if (typeof value === "string") {
|
|
82
|
+
const structuredValue = parseStructuredValue(value);
|
|
83
|
+
return structuredValue ? containsCredentialBearingUrlField(structuredValue, fieldNames, visited) : false;
|
|
84
|
+
}
|
|
85
|
+
if (!value || typeof value !== "object" || visited.has(value)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
visited.add(value);
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
return value.some((item) => containsCredentialBearingUrlField(item, fieldNames, visited));
|
|
91
|
+
}
|
|
92
|
+
return Object.entries(value).some(([key, item]) => {
|
|
93
|
+
if (pathSegments(key).some((segment) => fieldNames.has(segment)) && containsUrlUserInfo(item)) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return containsCredentialBearingUrlField(item, fieldNames, visited);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function redactUrlUserInfo(value) {
|
|
100
|
+
return value.replace(/([a-z][a-z\d+.-]*:\/\/)([^/?#\s]+)@/gi, "$1***:***@");
|
|
101
|
+
}
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
URL_USERINFO_NOT_ALLOWED,
|
|
105
|
+
assertUrlHasNoUserInfo,
|
|
106
|
+
containsCredentialBearingUrlField,
|
|
107
|
+
hasUrlUserInfo,
|
|
108
|
+
redactUrlUserInfo
|
|
109
|
+
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"displayName": "Git Manager",
|
|
4
4
|
"displayName.zh-CN": "Git 管理器",
|
|
5
5
|
"description": "Manage Git repositories with PAT authentication - pull, push, fetch, diff, file browsing",
|
|
6
|
-
"version": "1.2.
|
|
6
|
+
"version": "1.2.24",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/server/index.js",
|
|
9
9
|
"files": [
|
|
@@ -279,7 +279,7 @@ export const RepositoryConfig: React.FC = () => {
|
|
|
279
279
|
}}
|
|
280
280
|
width={520}
|
|
281
281
|
>
|
|
282
|
-
<Form form={form} layout="vertical" initialValues={{ defaultBranch: 'main' }}>
|
|
282
|
+
<Form form={form} layout="vertical" initialValues={{ defaultBranch: 'main', registryExportEnabled: false }}>
|
|
283
283
|
<Form.Item name="name" label={t('Repository Name')} rules={[{ required: true }]}>
|
|
284
284
|
<Input placeholder="my-project" />
|
|
285
285
|
</Form.Item>
|
|
@@ -307,6 +307,9 @@ export const RepositoryConfig: React.FC = () => {
|
|
|
307
307
|
<Form.Item name="defaultBranch" label={t('Default Branch')}>
|
|
308
308
|
<Input placeholder="main" />
|
|
309
309
|
</Form.Item>
|
|
310
|
+
<Form.Item name="registryExportEnabled" label={t('Allow Skill Registry export')} valuePropName="checked">
|
|
311
|
+
<Switch />
|
|
312
|
+
</Form.Item>
|
|
310
313
|
<Form.Item
|
|
311
314
|
name="autoReviewFlowId"
|
|
312
315
|
label={t('Primary Auto Review Flow')}
|
package/src/locale/en-US.json
CHANGED
|
@@ -290,7 +290,8 @@
|
|
|
290
290
|
"Policy": "Policy",
|
|
291
291
|
"Split SHA": "Split SHA",
|
|
292
292
|
"Target before": "Target before",
|
|
293
|
-
"Target after": "Target after"
|
|
294
|
-
|
|
295
|
-
|
|
293
|
+
"Target after": "Target after",
|
|
294
|
+
"Execution mode": "Execution mode",
|
|
295
|
+
"App process": "App process",
|
|
296
|
+
"Credential-bearing URLs are not allowed": "Credential-bearing URLs are not allowed"
|
|
296
297
|
}
|
package/src/locale/vi-VN.json
CHANGED
|
@@ -285,7 +285,8 @@
|
|
|
285
285
|
"Policy": "Chính sách",
|
|
286
286
|
"Split SHA": "SHA subtree",
|
|
287
287
|
"Target before": "Nhánh đích trước đó",
|
|
288
|
-
"Target after": "Nhánh đích sau đó"
|
|
289
|
-
|
|
290
|
-
|
|
288
|
+
"Target after": "Nhánh đích sau đó",
|
|
289
|
+
"Execution mode": "Chế độ thực thi",
|
|
290
|
+
"App process": "App process",
|
|
291
|
+
"Credential-bearing URLs are not allowed": "URL không được chứa tên người dùng hoặc thông tin xác thực"
|
|
291
292
|
}
|
package/src/locale/zh-CN.json
CHANGED
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
"Split SHA": "拆分 SHA",
|
|
45
45
|
"Target before": "更新前目标",
|
|
46
46
|
"Target after": "更新后目标",
|
|
47
|
-
"Error": "错误"
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
"Error": "错误",
|
|
48
|
+
"Execution mode": "执行模式",
|
|
49
|
+
"App process": "应用进程",
|
|
50
|
+
"Credential-bearing URLs are not allowed": "URL 中不允许包含用户名或凭据"
|
|
50
51
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Context } from '@nocobase/actions';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { getRepo } from '../actions/git-actions';
|
|
5
|
+
|
|
6
|
+
describe('Git Manager git actions', () => {
|
|
7
|
+
it('uses the repository ID from the request body over the URL parameter', async () => {
|
|
8
|
+
const repository = { id: 20 };
|
|
9
|
+
const findOne = vi.fn().mockResolvedValue(repository);
|
|
10
|
+
const context = {
|
|
11
|
+
action: { params: { repositoryId: 10 } },
|
|
12
|
+
request: { body: { repositoryId: 20 } },
|
|
13
|
+
db: {
|
|
14
|
+
getRepository: vi.fn().mockReturnValue({ findOne }),
|
|
15
|
+
},
|
|
16
|
+
throw: vi.fn(),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const result = await getRepo(context as unknown as Context);
|
|
20
|
+
|
|
21
|
+
expect(findOne).toHaveBeenCalledWith({ filterByTk: 20 });
|
|
22
|
+
expect(result).toBe(repository);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { isGitConfigurationUrlMutation } from '../plugin';
|
|
4
|
+
|
|
5
|
+
describe('Git Manager generic URL mutation policy', () => {
|
|
6
|
+
it('covers direct and association collection create/update routes', () => {
|
|
7
|
+
expect(isGitConfigurationUrlMutation('gitRepositories', 'create')).toBe(true);
|
|
8
|
+
expect(isGitConfigurationUrlMutation('gitAccounts', 'update')).toBe(true);
|
|
9
|
+
expect(isGitConfigurationUrlMutation('gitAccounts.repositories', 'update')).toBe(true);
|
|
10
|
+
expect(isGitConfigurationUrlMutation('gitRepositories.10.gitAccount', 'create')).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('does not treat a read or a custom Git Manager action as a generic URL mutation', () => {
|
|
14
|
+
expect(isGitConfigurationUrlMutation('gitAccounts.repositories', 'list')).toBe(false);
|
|
15
|
+
expect(isGitConfigurationUrlMutation('gitManager', 'clone')).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Context } from '@nocobase/actions';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
vi.mock('../poller', () => ({
|
|
5
|
+
pollAllRepos: vi.fn(),
|
|
6
|
+
pollOneRepo: vi.fn(),
|
|
7
|
+
getPollerStatus: vi.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
import { pollNow } from '../actions/poller';
|
|
11
|
+
import { pollAllRepos, pollOneRepo } from '../poller';
|
|
12
|
+
|
|
13
|
+
describe('Git Manager poll action', () => {
|
|
14
|
+
it('uses a repository ID sent in the request body instead of polling every repository', async () => {
|
|
15
|
+
const repository = { id: 10 };
|
|
16
|
+
vi.mocked(pollOneRepo).mockResolvedValue({ scanned: 1, triggered: 0 });
|
|
17
|
+
const context = {
|
|
18
|
+
action: { params: {} },
|
|
19
|
+
request: { body: { repositoryId: 10 } },
|
|
20
|
+
app: {},
|
|
21
|
+
db: {
|
|
22
|
+
getRepository: vi.fn().mockReturnValue({
|
|
23
|
+
findOne: vi.fn().mockResolvedValue(repository),
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
throw: vi.fn(),
|
|
27
|
+
body: undefined as unknown,
|
|
28
|
+
};
|
|
29
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
30
|
+
|
|
31
|
+
await pollNow(context as unknown as Context, next);
|
|
32
|
+
|
|
33
|
+
expect(pollOneRepo).toHaveBeenCalledWith(context.app, repository);
|
|
34
|
+
expect(pollAllRepos).not.toHaveBeenCalled();
|
|
35
|
+
expect(context.body).toEqual({ success: true, data: { scanned: 1, triggered: 0 } });
|
|
36
|
+
});
|
|
37
|
+
});
|