plugin-git-manager 1.2.23 → 1.2.26
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/900.acf7d1fa22f95e71.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/900.f32b9dc85249fc0a.js +10 -0
- 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 +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 +149 -32
- 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 +4 -2
- package/src/client/components/RunReviewButton.tsx +437 -436
- package/src/client/index.tsx +2 -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 +473 -315
- 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
- package/dist/client/900.ee2fa037aff389e2.js +0 -10
- package/dist/client-v2/900.bef1c41d267e50c5.js +0 -10
|
@@ -28,32 +28,53 @@ 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");
|
|
41
|
-
|
|
50
|
+
var import_repository_access = require("../repository-access");
|
|
51
|
+
function positiveLimit(value, fallback, maximum = Number.MAX_SAFE_INTEGER) {
|
|
42
52
|
const parsed = Number(value);
|
|
43
53
|
return Number.isSafeInteger(parsed) && parsed > 0 && parsed <= maximum ? parsed : fallback;
|
|
44
54
|
}
|
|
45
|
-
const DEFAULT_REGISTRY_GIT_CONTENT_LIMITS =
|
|
46
|
-
maxFileBytes
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
)
|
|
53
|
-
|
|
55
|
+
const DEFAULT_REGISTRY_GIT_CONTENT_LIMITS = {
|
|
56
|
+
get maxFileBytes() {
|
|
57
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_FILE_BYTES, 10 * 1024 * 1024);
|
|
58
|
+
},
|
|
59
|
+
get maxTreeEntries() {
|
|
60
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_ENTRIES, 5e3);
|
|
61
|
+
},
|
|
62
|
+
get maxTreeOutputBytes() {
|
|
63
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_OUTPUT_BYTES, 4 * 1024 * 1024);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
54
66
|
const REGISTRY_EXPORT_NOT_GRANTED = "REGISTRY_EXPORT_NOT_GRANTED";
|
|
67
|
+
const REGISTRY_REPOSITORY_ACCESS_DENIED = "REGISTRY_REPOSITORY_ACCESS_DENIED";
|
|
68
|
+
const SKILL_HUB_REPOSITORY_ACCESS_DENIED = "SKILL_HUB_REPOSITORY_ACCESS_DENIED";
|
|
55
69
|
const REGISTRY_CONTENT_LIMIT_EXCEEDED = "REGISTRY_CONTENT_LIMIT_EXCEEDED";
|
|
56
70
|
const REGISTRY_GIT_FILE_NOT_FOUND = "REGISTRY_GIT_FILE_NOT_FOUND";
|
|
71
|
+
const REGISTRY_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
72
|
+
const REGISTRY_GIT_CONTENT_CAPABILITIES = [
|
|
73
|
+
"registry-content-with-actor",
|
|
74
|
+
"registry-content-authorize-source"
|
|
75
|
+
];
|
|
76
|
+
const SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
77
|
+
const SKILL_HUB_GIT_CONTENT_CAPABILITIES = ["skill-hub-content-with-actor"];
|
|
57
78
|
const DEFAULT_GIT_TIMEOUT_MS = 3e4;
|
|
58
79
|
const MAX_STDERR_BYTES = 64 * 1024;
|
|
59
80
|
class RegistryExportNotGrantedError extends Error {
|
|
@@ -63,6 +84,20 @@ class RegistryExportNotGrantedError extends Error {
|
|
|
63
84
|
this.name = "RegistryExportNotGrantedError";
|
|
64
85
|
}
|
|
65
86
|
}
|
|
87
|
+
class RegistryRepositoryAccessDeniedError extends Error {
|
|
88
|
+
code = REGISTRY_REPOSITORY_ACCESS_DENIED;
|
|
89
|
+
constructor() {
|
|
90
|
+
super("The current actor is not authorized to read this repository for registry export.");
|
|
91
|
+
this.name = "RegistryRepositoryAccessDeniedError";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
class SkillHubRepositoryAccessDeniedError extends Error {
|
|
95
|
+
code = SKILL_HUB_REPOSITORY_ACCESS_DENIED;
|
|
96
|
+
constructor() {
|
|
97
|
+
super("The current actor is not authorized to read this repository for Skill Hub.");
|
|
98
|
+
this.name = "SkillHubRepositoryAccessDeniedError";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
66
101
|
class RegistryContentLimitError extends Error {
|
|
67
102
|
code = REGISTRY_CONTENT_LIMIT_EXCEEDED;
|
|
68
103
|
constructor(message) {
|
|
@@ -77,6 +112,22 @@ class RegistryGitFileNotFoundError extends Error {
|
|
|
77
112
|
this.name = "RegistryGitFileNotFoundError";
|
|
78
113
|
}
|
|
79
114
|
}
|
|
115
|
+
const REGISTRY_CONTENT_ACCESS_POLICY = {
|
|
116
|
+
contractVersion: REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
117
|
+
capabilities: REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
118
|
+
allowsSystemScheduledSync: true,
|
|
119
|
+
requiresRegistryExport: true,
|
|
120
|
+
createAccessDeniedError: () => new RegistryRepositoryAccessDeniedError(),
|
|
121
|
+
createRepositoryUnavailableError: () => new RegistryExportNotGrantedError()
|
|
122
|
+
};
|
|
123
|
+
const SKILL_HUB_CONTENT_ACCESS_POLICY = {
|
|
124
|
+
contractVersion: SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION,
|
|
125
|
+
capabilities: SKILL_HUB_GIT_CONTENT_CAPABILITIES,
|
|
126
|
+
allowsSystemScheduledSync: false,
|
|
127
|
+
requiresRegistryExport: false,
|
|
128
|
+
createAccessDeniedError: () => new SkillHubRepositoryAccessDeniedError(),
|
|
129
|
+
createRepositoryUnavailableError: () => new SkillHubRepositoryAccessDeniedError()
|
|
130
|
+
};
|
|
80
131
|
function boundedPositive(value, fallback, maximum) {
|
|
81
132
|
return Number.isSafeInteger(value) && Number(value) > 0 && Number(value) <= maximum ? Number(value) : fallback;
|
|
82
133
|
}
|
|
@@ -88,17 +139,17 @@ function runGitBuffer(localPath, args, maximumBytes, timeoutMs) {
|
|
|
88
139
|
let stderr = "";
|
|
89
140
|
let stderrBytes = 0;
|
|
90
141
|
let settled = false;
|
|
91
|
-
|
|
92
|
-
|
|
142
|
+
let pendingFailure;
|
|
143
|
+
const stop = (error) => {
|
|
144
|
+
if (settled || pendingFailure) {
|
|
93
145
|
return;
|
|
94
146
|
}
|
|
95
|
-
|
|
147
|
+
pendingFailure = error;
|
|
96
148
|
clearTimeout(timer);
|
|
97
149
|
child.kill();
|
|
98
|
-
reject(error);
|
|
99
150
|
};
|
|
100
151
|
const timer = setTimeout(() => {
|
|
101
|
-
|
|
152
|
+
stop(new RegistryContentLimitError("Git registry read exceeded its execution timeout."));
|
|
102
153
|
}, timeoutMs);
|
|
103
154
|
child.stdout.on("data", (chunk) => {
|
|
104
155
|
if (settled) {
|
|
@@ -106,7 +157,7 @@ function runGitBuffer(localPath, args, maximumBytes, timeoutMs) {
|
|
|
106
157
|
}
|
|
107
158
|
outputBytes += chunk.length;
|
|
108
159
|
if (outputBytes > maximumBytes) {
|
|
109
|
-
|
|
160
|
+
stop(new RegistryContentLimitError("Git registry read exceeded its output limit."));
|
|
110
161
|
return;
|
|
111
162
|
}
|
|
112
163
|
chunks.push(chunk);
|
|
@@ -120,13 +171,22 @@ function runGitBuffer(localPath, args, maximumBytes, timeoutMs) {
|
|
|
120
171
|
stderrBytes += bounded.length;
|
|
121
172
|
stderr += bounded.toString("utf8");
|
|
122
173
|
});
|
|
123
|
-
child.once("error", (error) =>
|
|
174
|
+
child.once("error", (error) => {
|
|
175
|
+
if (!pendingFailure) {
|
|
176
|
+
pendingFailure = error;
|
|
177
|
+
clearTimeout(timer);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
124
180
|
child.once("close", (code) => {
|
|
125
181
|
if (settled) {
|
|
126
182
|
return;
|
|
127
183
|
}
|
|
128
184
|
settled = true;
|
|
129
185
|
clearTimeout(timer);
|
|
186
|
+
if (pendingFailure) {
|
|
187
|
+
reject(pendingFailure);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
130
190
|
if (code !== 0) {
|
|
131
191
|
if (/does not exist in|exists on disk, but not in|path .* does not exist/i.test(stderr)) {
|
|
132
192
|
reject(new RegistryGitFileNotFoundError());
|
|
@@ -174,13 +234,27 @@ function parseTreeLine(line, rootPath) {
|
|
|
174
234
|
size: match[4] === "-" ? 0 : Number.parseInt(match[4], 10)
|
|
175
235
|
};
|
|
176
236
|
}
|
|
177
|
-
class
|
|
178
|
-
constructor(database, limits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS) {
|
|
237
|
+
class GitContentService {
|
|
238
|
+
constructor(database, limits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS, acl, accessPolicy = REGISTRY_CONTENT_ACCESS_POLICY) {
|
|
179
239
|
this.database = database;
|
|
180
240
|
this.limits = limits;
|
|
241
|
+
this.acl = acl;
|
|
242
|
+
this.accessPolicy = accessPolicy;
|
|
243
|
+
this.contractVersion = accessPolicy.contractVersion;
|
|
244
|
+
this.capabilities = accessPolicy.capabilities;
|
|
245
|
+
}
|
|
246
|
+
contractVersion;
|
|
247
|
+
capabilities;
|
|
248
|
+
/**
|
|
249
|
+
* Validates actor access before a cross-plugin service binds or reads a
|
|
250
|
+
* repository. The concrete service policy decides whether Registry export
|
|
251
|
+
* opt-in or scheduled system access is permitted.
|
|
252
|
+
*/
|
|
253
|
+
async assertRepositoryAccess(repositoryId, access) {
|
|
254
|
+
await this.findRepository(repositoryId, access);
|
|
181
255
|
}
|
|
182
|
-
async resolveCommit(repositoryId, ref) {
|
|
183
|
-
const repository = await this.findRepository(repositoryId);
|
|
256
|
+
async resolveCommit(repositoryId, ref, access) {
|
|
257
|
+
const repository = await this.findRepository(repositoryId, access);
|
|
184
258
|
const localPath = (0, import_git_actions.validateLocalPath)(repositoryValue(repository, "localPath"));
|
|
185
259
|
if (!(0, import_fs.existsSync)(localPath)) {
|
|
186
260
|
throw new Error("Repository directory does not exist. Clone the repository before reading its content.");
|
|
@@ -196,8 +270,8 @@ class RegistryGitContentService {
|
|
|
196
270
|
}
|
|
197
271
|
return result.toLowerCase();
|
|
198
272
|
}
|
|
199
|
-
async listTree(input) {
|
|
200
|
-
const repository = await this.findRepository(input.repositoryId);
|
|
273
|
+
async listTree(input, access) {
|
|
274
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
201
275
|
const localPath = (0, import_git_actions.validateLocalPath)(repositoryValue(repository, "localPath"));
|
|
202
276
|
if (!(0, import_fs.existsSync)(localPath)) {
|
|
203
277
|
throw new Error("Repository directory does not exist. Clone the repository before reading its content.");
|
|
@@ -217,8 +291,8 @@ class RegistryGitContentService {
|
|
|
217
291
|
}
|
|
218
292
|
return lines.map((line) => parseTreeLine(line, rootPath)).filter((entry) => entry !== null).sort((left, right) => left.path.localeCompare(right.path));
|
|
219
293
|
}
|
|
220
|
-
async readFile(input) {
|
|
221
|
-
const repository = await this.findRepository(input.repositoryId);
|
|
294
|
+
async readFile(input, access) {
|
|
295
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
222
296
|
const localPath = (0, import_git_actions.validateLocalPath)(repositoryValue(repository, "localPath"));
|
|
223
297
|
if (!(0, import_fs.existsSync)(localPath)) {
|
|
224
298
|
throw new Error("Repository directory does not exist. Clone the repository before reading its content.");
|
|
@@ -235,8 +309,8 @@ class RegistryGitContentService {
|
|
|
235
309
|
throw error;
|
|
236
310
|
}
|
|
237
311
|
}
|
|
238
|
-
async archiveTree(input) {
|
|
239
|
-
const repository = await this.findRepository(input.repositoryId);
|
|
312
|
+
async archiveTree(input, access) {
|
|
313
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
240
314
|
const localPath = (0, import_git_actions.validateLocalPath)(repositoryValue(repository, "localPath"));
|
|
241
315
|
if (!(0, import_fs.existsSync)(localPath)) {
|
|
242
316
|
throw new Error("Repository directory does not exist. Clone the repository before reading its content.");
|
|
@@ -265,17 +339,41 @@ class RegistryGitContentService {
|
|
|
265
339
|
});
|
|
266
340
|
});
|
|
267
341
|
}
|
|
268
|
-
async findRepository(repositoryId) {
|
|
342
|
+
async findRepository(repositoryId, access) {
|
|
343
|
+
await this.assertAccess(repositoryId, access);
|
|
269
344
|
const repository = await this.database.getRepository("gitRepositories").findOne({ filterByTk: repositoryId });
|
|
270
345
|
if (!repository) {
|
|
271
|
-
throw
|
|
346
|
+
throw this.accessPolicy.createRepositoryUnavailableError();
|
|
272
347
|
}
|
|
273
348
|
const repositoryModel = repository;
|
|
274
|
-
if (repositoryModel.get("registryExportEnabled") !== true) {
|
|
349
|
+
if (this.accessPolicy.requiresRegistryExport && repositoryModel.get("registryExportEnabled") !== true) {
|
|
275
350
|
throw new RegistryExportNotGrantedError();
|
|
276
351
|
}
|
|
277
352
|
return repositoryModel;
|
|
278
353
|
}
|
|
354
|
+
async assertAccess(repositoryId, access) {
|
|
355
|
+
if (!access) {
|
|
356
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
357
|
+
}
|
|
358
|
+
if (access.kind === "system") {
|
|
359
|
+
if (this.accessPolicy.allowsSystemScheduledSync && access.reason === "scheduled-sync") {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
363
|
+
}
|
|
364
|
+
if (access.kind !== "user" || !Array.isArray(access.roles) || !access.roles.every((role) => typeof role === "string")) {
|
|
365
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
366
|
+
}
|
|
367
|
+
const allowed = await (0, import_repository_access.hasRepositoryAccess)({
|
|
368
|
+
acl: this.acl,
|
|
369
|
+
roles: access.roles,
|
|
370
|
+
repositoryId,
|
|
371
|
+
action: "fileContent"
|
|
372
|
+
});
|
|
373
|
+
if (!allowed) {
|
|
374
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
375
|
+
}
|
|
376
|
+
}
|
|
279
377
|
assertCommitSha(value) {
|
|
280
378
|
const normalized = (0, import_git_actions.validateRef)(value);
|
|
281
379
|
if (!/^[a-f0-9]{40,64}$/i.test(normalized)) {
|
|
@@ -284,13 +382,32 @@ class RegistryGitContentService {
|
|
|
284
382
|
return normalized.toLowerCase();
|
|
285
383
|
}
|
|
286
384
|
}
|
|
385
|
+
class RegistryGitContentService extends GitContentService {
|
|
386
|
+
constructor(database, limits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS, acl) {
|
|
387
|
+
super(database, limits, acl, REGISTRY_CONTENT_ACCESS_POLICY);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
class SkillHubGitContentService extends GitContentService {
|
|
391
|
+
constructor(database, limits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS, acl) {
|
|
392
|
+
super(database, limits, acl, SKILL_HUB_CONTENT_ACCESS_POLICY);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
287
395
|
// Annotate the CommonJS export names for ESM import in node:
|
|
288
396
|
0 && (module.exports = {
|
|
289
397
|
REGISTRY_CONTENT_LIMIT_EXCEEDED,
|
|
290
398
|
REGISTRY_EXPORT_NOT_GRANTED,
|
|
399
|
+
REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
400
|
+
REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
291
401
|
REGISTRY_GIT_FILE_NOT_FOUND,
|
|
402
|
+
REGISTRY_REPOSITORY_ACCESS_DENIED,
|
|
292
403
|
RegistryContentLimitError,
|
|
293
404
|
RegistryExportNotGrantedError,
|
|
294
405
|
RegistryGitContentService,
|
|
295
|
-
RegistryGitFileNotFoundError
|
|
406
|
+
RegistryGitFileNotFoundError,
|
|
407
|
+
RegistryRepositoryAccessDeniedError,
|
|
408
|
+
SKILL_HUB_GIT_CONTENT_CAPABILITIES,
|
|
409
|
+
SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION,
|
|
410
|
+
SKILL_HUB_REPOSITORY_ACCESS_DENIED,
|
|
411
|
+
SkillHubGitContentService,
|
|
412
|
+
SkillHubRepositoryAccessDeniedError
|
|
296
413
|
});
|
|
@@ -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.26",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/server/index.js",
|
|
9
9
|
"files": [
|
|
@@ -38,4 +38,6 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"simple-git": "^3.27.0"
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
,
|
|
42
|
+
"keywords": "System management"
|
|
43
|
+
}
|