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
|
@@ -26,10 +26,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
26
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
27
|
var repository_access_exports = {};
|
|
28
28
|
__export(repository_access_exports, {
|
|
29
|
-
enforceRepositoryAccess: () => enforceRepositoryAccess
|
|
29
|
+
enforceRepositoryAccess: () => enforceRepositoryAccess,
|
|
30
|
+
enforceRepositoryCollectionAccess: () => enforceRepositoryCollectionAccess,
|
|
31
|
+
getEffectiveActionParams: () => getEffectiveActionParams,
|
|
32
|
+
hasRepositoryAccess: () => hasRepositoryAccess,
|
|
33
|
+
resolveRepositoryScope: () => resolveRepositoryScope,
|
|
34
|
+
scopeIncludesRepository: () => scopeIncludesRepository
|
|
30
35
|
});
|
|
31
36
|
module.exports = __toCommonJS(repository_access_exports);
|
|
32
|
-
const
|
|
37
|
+
const REPOSITORY_ID_ACTIONS = /* @__PURE__ */ new Set([
|
|
33
38
|
"clone",
|
|
34
39
|
"pull",
|
|
35
40
|
"push",
|
|
@@ -46,47 +51,520 @@ const REPOSITORY_SCOPED_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
46
51
|
"mergeRequestDetail",
|
|
47
52
|
"mergeRequestNotes",
|
|
48
53
|
"triggerReview",
|
|
49
|
-
"pollNow",
|
|
50
|
-
"subtreePreview",
|
|
51
54
|
"subtreeOptions"
|
|
52
55
|
]);
|
|
56
|
+
const SUBTREE_CONFIG_ACTIONS = /* @__PURE__ */ new Set(["subtreePreview", "subtreeRun", "subtreeReplace"]);
|
|
57
|
+
const REVIEW_ID_ACTIONS = /* @__PURE__ */ new Set(["reviewApprovePost", "reviewReject"]);
|
|
58
|
+
function asRecord(value) {
|
|
59
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
60
|
+
}
|
|
61
|
+
function asRepositoryId(value) {
|
|
62
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
63
|
+
if (typeof value === "string" && value.trim()) return value;
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
function getRecordValue(record, attribute) {
|
|
67
|
+
if (!record || typeof record !== "object") return void 0;
|
|
68
|
+
const model = record;
|
|
69
|
+
return typeof model.get === "function" ? model.get(attribute) : model[attribute];
|
|
70
|
+
}
|
|
71
|
+
function getEffectiveActionParams(ctx) {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
const params = asRecord((_a = ctx.action) == null ? void 0 : _a.params);
|
|
74
|
+
return {
|
|
75
|
+
...params,
|
|
76
|
+
...asRecord(params.values),
|
|
77
|
+
...asRecord((_b = ctx.request) == null ? void 0 : _b.body)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function supportedRepositoryIds(ids) {
|
|
81
|
+
const uniqueIds = [];
|
|
82
|
+
for (const id of ids) {
|
|
83
|
+
if (!uniqueIds.some((candidate) => String(candidate) === String(id))) {
|
|
84
|
+
uniqueIds.push(id);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { ids: uniqueIds, unrestricted: false, supported: true };
|
|
88
|
+
}
|
|
89
|
+
function unsupportedRepositoryScope() {
|
|
90
|
+
return { ids: [], unrestricted: false, supported: false };
|
|
91
|
+
}
|
|
92
|
+
function resolveRepositoryScopeBranches(operator, branches) {
|
|
93
|
+
const resolutions = branches.map(resolveRepositoryScope);
|
|
94
|
+
if (resolutions.some((resolution) => !resolution.supported)) {
|
|
95
|
+
return unsupportedRepositoryScope();
|
|
96
|
+
}
|
|
97
|
+
if (operator === "$or") {
|
|
98
|
+
if (resolutions.some((resolution) => resolution.unrestricted)) {
|
|
99
|
+
return { ids: [], unrestricted: true, supported: true };
|
|
100
|
+
}
|
|
101
|
+
return supportedRepositoryIds(resolutions.flatMap((resolution) => resolution.ids));
|
|
102
|
+
}
|
|
103
|
+
const restricted = resolutions.filter((resolution) => !resolution.unrestricted);
|
|
104
|
+
if (restricted.length === 0) {
|
|
105
|
+
return { ids: [], unrestricted: true, supported: true };
|
|
106
|
+
}
|
|
107
|
+
const [first, ...rest] = restricted;
|
|
108
|
+
return supportedRepositoryIds(
|
|
109
|
+
first.ids.filter(
|
|
110
|
+
(id) => rest.every((resolution) => resolution.ids.some((candidate) => String(candidate) === String(id)))
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
function resolveRepositoryScope(scope) {
|
|
115
|
+
if (scope == null) {
|
|
116
|
+
return { ids: [], unrestricted: true, supported: true };
|
|
117
|
+
}
|
|
118
|
+
if (typeof scope !== "object" || Array.isArray(scope)) {
|
|
119
|
+
return unsupportedRepositoryScope();
|
|
120
|
+
}
|
|
121
|
+
const condition = scope;
|
|
122
|
+
const keys = Object.keys(condition);
|
|
123
|
+
if (keys.length === 0) {
|
|
124
|
+
return { ids: [], unrestricted: true, supported: true };
|
|
125
|
+
}
|
|
126
|
+
const operator = keys.find((key) => key === "$and" || key === "$or");
|
|
127
|
+
if (operator) {
|
|
128
|
+
if (keys.length !== 1 || !Array.isArray(condition[operator])) {
|
|
129
|
+
return unsupportedRepositoryScope();
|
|
130
|
+
}
|
|
131
|
+
return resolveRepositoryScopeBranches(operator, condition[operator]);
|
|
132
|
+
}
|
|
133
|
+
if (keys.length !== 1 || !("id" in condition)) {
|
|
134
|
+
return unsupportedRepositoryScope();
|
|
135
|
+
}
|
|
136
|
+
const id = condition.id;
|
|
137
|
+
if (typeof id === "number" || typeof id === "string") {
|
|
138
|
+
return supportedRepositoryIds([id]);
|
|
139
|
+
}
|
|
140
|
+
if (!id || typeof id !== "object" || Array.isArray(id)) {
|
|
141
|
+
return unsupportedRepositoryScope();
|
|
142
|
+
}
|
|
143
|
+
const idCondition = id;
|
|
144
|
+
const idKeys = Object.keys(idCondition);
|
|
145
|
+
if (idKeys.length !== 1) {
|
|
146
|
+
return unsupportedRepositoryScope();
|
|
147
|
+
}
|
|
148
|
+
const equal = idCondition.$eq;
|
|
149
|
+
if (typeof equal === "number" || typeof equal === "string") {
|
|
150
|
+
return supportedRepositoryIds([equal]);
|
|
151
|
+
}
|
|
152
|
+
const included = idCondition.$in;
|
|
153
|
+
if (Array.isArray(included) && included.every((value) => typeof value === "number" || typeof value === "string")) {
|
|
154
|
+
return supportedRepositoryIds(included);
|
|
155
|
+
}
|
|
156
|
+
return unsupportedRepositoryScope();
|
|
157
|
+
}
|
|
53
158
|
function scopeIncludesRepository(filter, repositoryId) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
159
|
+
const scope = resolveRepositoryScope(filter);
|
|
160
|
+
return scope.supported && (scope.unrestricted || scope.ids.some((id) => String(id) === String(repositoryId)));
|
|
161
|
+
}
|
|
162
|
+
async function hasRepositoryAccess(input) {
|
|
163
|
+
var _a;
|
|
164
|
+
if (input.roles.includes("root")) {
|
|
165
|
+
return true;
|
|
59
166
|
}
|
|
60
|
-
if (
|
|
61
|
-
return
|
|
167
|
+
if (!input.acl) {
|
|
168
|
+
return false;
|
|
62
169
|
}
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
170
|
+
const permission = await input.acl.can({
|
|
171
|
+
roles: input.roles,
|
|
172
|
+
resource: "gitManager",
|
|
173
|
+
action: input.action || "fileContent"
|
|
174
|
+
});
|
|
175
|
+
return Boolean(permission && scopeIncludesRepository((_a = permission.params) == null ? void 0 : _a.filter, input.repositoryId));
|
|
176
|
+
}
|
|
177
|
+
async function hasUnrestrictedRepositoryAccess(input) {
|
|
178
|
+
var _a;
|
|
179
|
+
if (input.roles.includes("root")) return true;
|
|
180
|
+
if (!input.acl) return false;
|
|
181
|
+
const permission = await input.acl.can({
|
|
182
|
+
roles: input.roles,
|
|
183
|
+
resource: "gitManager",
|
|
184
|
+
action: input.action
|
|
185
|
+
});
|
|
186
|
+
const scope = resolveRepositoryScope((_a = permission == null ? void 0 : permission.params) == null ? void 0 : _a.filter);
|
|
187
|
+
return Boolean(permission && scope.supported && scope.unrestricted);
|
|
188
|
+
}
|
|
189
|
+
const COLLECTION_SCOPE_FIELDS = {
|
|
190
|
+
gitRepositories: "id",
|
|
191
|
+
gitReviewFlows: "repositoryId",
|
|
192
|
+
gitCodeReviews: "repositoryId",
|
|
193
|
+
gitSubtreeConfigs: "repositoryId",
|
|
194
|
+
gitSubtreeRuns: "config.repositoryId"
|
|
195
|
+
};
|
|
196
|
+
const STANDARD_COLLECTION_ACTIONS = /* @__PURE__ */ new Set(["list", "get", "create", "update", "destroy"]);
|
|
197
|
+
function currentRoles(ctx) {
|
|
198
|
+
var _a;
|
|
199
|
+
const rawRoles = (_a = ctx.state) == null ? void 0 : _a.currentRoles;
|
|
200
|
+
const roles = Array.isArray(rawRoles) ? rawRoles.filter((role) => typeof role === "string") : [];
|
|
201
|
+
if (Array.isArray(rawRoles) && roles.length !== rawRoles.length) {
|
|
202
|
+
return ctx.throw(403, "Permission denied");
|
|
67
203
|
}
|
|
68
|
-
return
|
|
204
|
+
return roles;
|
|
69
205
|
}
|
|
70
|
-
|
|
206
|
+
function scopedCollectionName(ctx) {
|
|
71
207
|
var _a, _b, _c, _d, _e;
|
|
72
|
-
|
|
208
|
+
let targetCollectionName;
|
|
209
|
+
try {
|
|
210
|
+
targetCollectionName = (_c = (_b = (_a = ctx.getCurrentRepository) == null ? void 0 : _a.call(ctx)) == null ? void 0 : _b.targetCollection) == null ? void 0 : _c.name;
|
|
211
|
+
} catch {
|
|
212
|
+
}
|
|
213
|
+
if (targetCollectionName && Object.prototype.hasOwnProperty.call(COLLECTION_SCOPE_FIELDS, targetCollectionName)) {
|
|
214
|
+
return targetCollectionName;
|
|
215
|
+
}
|
|
216
|
+
if (targetCollectionName === "gitAccounts") {
|
|
217
|
+
return targetCollectionName;
|
|
218
|
+
}
|
|
219
|
+
const params = asRecord((_d = ctx.action) == null ? void 0 : _d.params);
|
|
220
|
+
const candidates = [(_e = ctx.action) == null ? void 0 : _e.resourceName, params.resourceName, params.associatedName, params.targetCollection].filter((value) => typeof value === "string").flatMap((value) => value.split("."));
|
|
221
|
+
return candidates.find(
|
|
222
|
+
(candidate) => candidate === "gitAccounts" || Object.prototype.hasOwnProperty.call(COLLECTION_SCOPE_FIELDS, candidate)
|
|
223
|
+
) || null;
|
|
224
|
+
}
|
|
225
|
+
function collectionFilter(collectionName, ids) {
|
|
226
|
+
if (collectionName === "gitSubtreeRuns") {
|
|
227
|
+
return { config: { repositoryId: { $in: ids } } };
|
|
228
|
+
}
|
|
229
|
+
return { [COLLECTION_SCOPE_FIELDS[collectionName]]: { $in: ids } };
|
|
230
|
+
}
|
|
231
|
+
function effectiveMutationValues(ctx) {
|
|
232
|
+
var _a;
|
|
233
|
+
const body = asRecord((_a = ctx.request) == null ? void 0 : _a.body);
|
|
234
|
+
return { ...asRecord(body.values), ...getEffectiveActionParams(ctx) };
|
|
235
|
+
}
|
|
236
|
+
function rejectTargetCollectionOverride(ctx, collectionName) {
|
|
237
|
+
var _a, _b;
|
|
238
|
+
const actionParams = asRecord((_a = ctx.action) == null ? void 0 : _a.params);
|
|
239
|
+
const requestBody = asRecord((_b = ctx.request) == null ? void 0 : _b.body);
|
|
240
|
+
const actionValues = asRecord(actionParams.values);
|
|
241
|
+
const bodyValues = asRecord(requestBody.values);
|
|
242
|
+
const requestedCollections = [
|
|
243
|
+
actionParams.targetCollection,
|
|
244
|
+
actionParams.__collection,
|
|
245
|
+
actionValues.targetCollection,
|
|
246
|
+
actionValues.__collection,
|
|
247
|
+
requestBody.targetCollection,
|
|
248
|
+
requestBody.__collection,
|
|
249
|
+
bodyValues.targetCollection,
|
|
250
|
+
bodyValues.__collection
|
|
251
|
+
];
|
|
252
|
+
for (const requestedCollection of requestedCollections) {
|
|
253
|
+
if (requestedCollection == null || requestedCollection === collectionName) continue;
|
|
254
|
+
ctx.throw(403, "Permission denied");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function rejectScopedRepositoryConnectionMutation(ctx) {
|
|
258
|
+
var _a, _b, _c;
|
|
259
|
+
const valueSources = [(_a = ctx.action) == null ? void 0 : _a.params, ctx.query, (_b = ctx.request) == null ? void 0 : _b.query, (_c = ctx.request) == null ? void 0 : _c.body];
|
|
260
|
+
if (valueSources.some((values) => containsMutationField(values, REPOSITORY_CONNECTION_FIELD_SEGMENTS))) {
|
|
261
|
+
ctx.throw(403, "Permission denied");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function rejectScopedAssociationMutation(ctx, associationSegments) {
|
|
265
|
+
var _a, _b, _c;
|
|
266
|
+
const valueSources = [(_a = ctx.action) == null ? void 0 : _a.params, ctx.query, (_b = ctx.request) == null ? void 0 : _b.query, (_c = ctx.request) == null ? void 0 : _c.body];
|
|
267
|
+
if (valueSources.some((values) => containsMutationField(values, associationSegments))) {
|
|
268
|
+
ctx.throw(403, "Permission denied");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function rejectScopedBulkMutationValues(ctx, actionName) {
|
|
272
|
+
var _a, _b;
|
|
273
|
+
if (actionName !== "create" && actionName !== "update") {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const actionParams = asRecord((_a = ctx.action) == null ? void 0 : _a.params);
|
|
277
|
+
const requestBody = (_b = ctx.request) == null ? void 0 : _b.body;
|
|
278
|
+
const bodyValues = asRecord(requestBody).values;
|
|
279
|
+
if (Array.isArray(actionParams.values) || Array.isArray(requestBody) || Array.isArray(bodyValues)) {
|
|
280
|
+
ctx.throw(403, "Permission denied");
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const ASSOCIATION_READ_PARAM_KEYS = ["appends", "include", "fields"];
|
|
284
|
+
const CREDENTIAL_ASSOCIATION_SEGMENTS = /* @__PURE__ */ new Set(["gitAccount", "gitAccounts"]);
|
|
285
|
+
const REPOSITORY_CONNECTION_FIELD_SEGMENTS = /* @__PURE__ */ new Set(["gitAccount", "gitAccountId", "repoUrl", "localPath"]);
|
|
286
|
+
const REPOSITORY_ASSOCIATION_SEGMENTS = /* @__PURE__ */ new Set(["repository"]);
|
|
287
|
+
const SUBTREE_RUN_ASSOCIATION_SEGMENTS = /* @__PURE__ */ new Set(["config"]);
|
|
288
|
+
function pathSegments(value) {
|
|
289
|
+
return value.split(/[.[\],:/()=\s'"]+/);
|
|
290
|
+
}
|
|
291
|
+
function containsCredentialAssociationSegment(value) {
|
|
292
|
+
return pathSegments(value).some((segment) => CREDENTIAL_ASSOCIATION_SEGMENTS.has(segment));
|
|
293
|
+
}
|
|
294
|
+
function containsMutationField(value, fieldSegments, visited = /* @__PURE__ */ new WeakSet()) {
|
|
295
|
+
if (!value || typeof value !== "object") {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
if (visited.has(value)) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
visited.add(value);
|
|
302
|
+
if (Array.isArray(value)) {
|
|
303
|
+
return value.some((item) => containsMutationField(item, fieldSegments, visited));
|
|
304
|
+
}
|
|
305
|
+
return Object.entries(value).some(
|
|
306
|
+
([key, item]) => pathSegments(key).some((segment) => fieldSegments.has(segment)) || containsMutationField(item, fieldSegments, visited)
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
function containsCredentialAssociation(value, visited = /* @__PURE__ */ new WeakSet()) {
|
|
310
|
+
if (typeof value === "string") {
|
|
311
|
+
return containsCredentialAssociationSegment(value);
|
|
312
|
+
}
|
|
313
|
+
if (!value || typeof value !== "object") {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
if (visited.has(value)) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
visited.add(value);
|
|
320
|
+
if (Array.isArray(value)) {
|
|
321
|
+
return value.some((item) => containsCredentialAssociation(item, visited));
|
|
322
|
+
}
|
|
323
|
+
return Object.entries(value).some(
|
|
324
|
+
([key, item]) => containsCredentialAssociationSegment(key) || containsCredentialAssociation(item, visited)
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
function isAssociationReadParamKey(key) {
|
|
328
|
+
return ASSOCIATION_READ_PARAM_KEYS.some(
|
|
329
|
+
(paramKey) => key === paramKey || key.startsWith(`${paramKey}[`) || key.startsWith(`${paramKey}.`)
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
function rejectScopedCredentialAssociationRoute(ctx) {
|
|
333
|
+
var _a, _b, _c, _d, _e, _f;
|
|
334
|
+
const actionParams = asRecord((_a = ctx.action) == null ? void 0 : _a.params);
|
|
335
|
+
const requestBody = asRecord((_b = ctx.request) == null ? void 0 : _b.body);
|
|
336
|
+
const routeValues = [
|
|
337
|
+
(_c = ctx.action) == null ? void 0 : _c.resourceName,
|
|
338
|
+
actionParams.resourceName,
|
|
339
|
+
actionParams.associatedName,
|
|
340
|
+
actionParams.targetCollection,
|
|
341
|
+
requestBody.resourceName,
|
|
342
|
+
requestBody.associatedName,
|
|
343
|
+
requestBody.targetCollection,
|
|
344
|
+
asRecord(actionParams.values).resourceName,
|
|
345
|
+
asRecord(actionParams.values).associatedName,
|
|
346
|
+
asRecord(actionParams.values).targetCollection,
|
|
347
|
+
asRecord(requestBody.values).resourceName,
|
|
348
|
+
asRecord(requestBody.values).associatedName,
|
|
349
|
+
asRecord(requestBody.values).targetCollection,
|
|
350
|
+
asRecord(ctx.query).resourceName,
|
|
351
|
+
asRecord(ctx.query).associatedName,
|
|
352
|
+
asRecord(ctx.query).targetCollection,
|
|
353
|
+
asRecord((_d = ctx.request) == null ? void 0 : _d.query).resourceName,
|
|
354
|
+
asRecord((_e = ctx.request) == null ? void 0 : _e.query).associatedName,
|
|
355
|
+
asRecord((_f = ctx.request) == null ? void 0 : _f.query).targetCollection
|
|
356
|
+
];
|
|
357
|
+
if (routeValues.some((value) => typeof value === "string" && containsCredentialAssociationSegment(value))) {
|
|
358
|
+
ctx.throw(403, "Permission denied");
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function rejectScopedRepositoryCredentialAssociationRead(ctx, actionName) {
|
|
362
|
+
var _a, _b, _c;
|
|
363
|
+
if (actionName !== "list" && actionName !== "get") {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const actionParams = asRecord((_a = ctx.action) == null ? void 0 : _a.params);
|
|
367
|
+
const requestBody = asRecord((_b = ctx.request) == null ? void 0 : _b.body);
|
|
368
|
+
const valueSources = [
|
|
369
|
+
actionParams,
|
|
370
|
+
asRecord(actionParams.values),
|
|
371
|
+
asRecord(ctx.query),
|
|
372
|
+
asRecord((_c = ctx.request) == null ? void 0 : _c.query),
|
|
373
|
+
requestBody,
|
|
374
|
+
asRecord(requestBody.values)
|
|
375
|
+
];
|
|
376
|
+
for (const values of valueSources) {
|
|
377
|
+
for (const [key, value] of Object.entries(values)) {
|
|
378
|
+
if (isAssociationReadParamKey(key) && containsCredentialAssociation(value)) {
|
|
379
|
+
ctx.throw(403, "Permission denied");
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function scopeAllowsRepository(scope, repositoryId) {
|
|
385
|
+
return scope.unrestricted || scope.ids.some((id) => String(id) === String(repositoryId));
|
|
386
|
+
}
|
|
387
|
+
function hasOwn(object, key) {
|
|
388
|
+
return Object.prototype.hasOwnProperty.call(object, key);
|
|
389
|
+
}
|
|
390
|
+
function requireScopedRepositoryValue(ctx, values, scope, actionName) {
|
|
391
|
+
if (hasOwn(values, "repository")) {
|
|
392
|
+
ctx.throw(403, "Permission denied");
|
|
393
|
+
}
|
|
394
|
+
if (!hasOwn(values, "repositoryId")) {
|
|
395
|
+
if (actionName === "create") {
|
|
396
|
+
ctx.throw(400, "repositoryId is required");
|
|
397
|
+
}
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const repositoryId = asRepositoryId(values.repositoryId);
|
|
401
|
+
if (repositoryId == null || !scopeAllowsRepository(scope, repositoryId)) {
|
|
402
|
+
ctx.throw(403, "Permission denied");
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
async function requireScopedRunConfigValue(ctx, values, scope, actionName) {
|
|
406
|
+
if (hasOwn(values, "config")) {
|
|
407
|
+
ctx.throw(403, "Permission denied");
|
|
408
|
+
}
|
|
409
|
+
if (!hasOwn(values, "configId")) {
|
|
410
|
+
if (actionName === "create") {
|
|
411
|
+
ctx.throw(400, "configId is required");
|
|
412
|
+
}
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
const configId = asRepositoryId(values.configId);
|
|
416
|
+
const database = ctx.db;
|
|
417
|
+
if (configId == null || !database) {
|
|
418
|
+
ctx.throw(403, "Permission denied");
|
|
419
|
+
}
|
|
420
|
+
const config = await database.getRepository("gitSubtreeConfigs").findOne({ filterByTk: configId });
|
|
421
|
+
if (!config) {
|
|
422
|
+
ctx.throw(404, "Subtree configuration not found");
|
|
423
|
+
}
|
|
424
|
+
const repositoryId = asRepositoryId(getRecordValue(config, "repositoryId"));
|
|
425
|
+
if (repositoryId == null || !scopeAllowsRepository(scope, repositoryId)) {
|
|
426
|
+
ctx.throw(403, "Permission denied");
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
async function enforceRepositoryCollectionAccess(ctx, next) {
|
|
430
|
+
var _a, _b, _c;
|
|
431
|
+
const collectionName = scopedCollectionName(ctx);
|
|
432
|
+
if (!collectionName) {
|
|
433
|
+
await next();
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
rejectTargetCollectionOverride(ctx, collectionName);
|
|
437
|
+
const roles = currentRoles(ctx);
|
|
438
|
+
if (roles.includes("root")) {
|
|
439
|
+
await next();
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const repositoryPermission = await ctx.app.acl.can({
|
|
443
|
+
roles,
|
|
444
|
+
resource: "gitRepositories",
|
|
445
|
+
action: "list"
|
|
446
|
+
});
|
|
447
|
+
if (!repositoryPermission) {
|
|
448
|
+
await next();
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
const scope = resolveRepositoryScope((_a = repositoryPermission.params) == null ? void 0 : _a.filter);
|
|
452
|
+
if (!scope.supported) {
|
|
453
|
+
ctx.throw(403, "Permission denied");
|
|
454
|
+
}
|
|
455
|
+
if (scope.unrestricted) {
|
|
456
|
+
await next();
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const actionName = (_b = ctx.action) == null ? void 0 : _b.actionName;
|
|
460
|
+
if (!actionName || !STANDARD_COLLECTION_ACTIONS.has(actionName)) {
|
|
461
|
+
ctx.throw(403, "Permission denied");
|
|
462
|
+
}
|
|
463
|
+
if (collectionName === "gitAccounts") {
|
|
464
|
+
ctx.throw(403, "Permission denied");
|
|
465
|
+
}
|
|
466
|
+
if (collectionName === "gitCodeReviews" && (actionName === "create" || actionName === "update")) {
|
|
467
|
+
ctx.throw(403, "Permission denied");
|
|
468
|
+
}
|
|
469
|
+
rejectScopedCredentialAssociationRoute(ctx);
|
|
470
|
+
rejectScopedRepositoryCredentialAssociationRead(ctx, actionName);
|
|
471
|
+
rejectScopedBulkMutationValues(ctx, actionName);
|
|
472
|
+
const mergeParams = (_c = ctx.action) == null ? void 0 : _c.mergeParams;
|
|
473
|
+
if (!mergeParams) {
|
|
474
|
+
ctx.throw(403, "Permission denied");
|
|
475
|
+
}
|
|
476
|
+
mergeParams({ filter: collectionFilter(collectionName, scope.ids) });
|
|
477
|
+
if (actionName === "create" && collectionName === "gitRepositories") {
|
|
478
|
+
ctx.throw(403, "Permission denied");
|
|
479
|
+
}
|
|
480
|
+
if (actionName === "create" || actionName === "update") {
|
|
481
|
+
const values = effectiveMutationValues(ctx);
|
|
482
|
+
if (collectionName === "gitSubtreeRuns") {
|
|
483
|
+
rejectScopedAssociationMutation(ctx, SUBTREE_RUN_ASSOCIATION_SEGMENTS);
|
|
484
|
+
await requireScopedRunConfigValue(ctx, values, scope, actionName);
|
|
485
|
+
} else if (collectionName === "gitRepositories") {
|
|
486
|
+
if (actionName === "update") {
|
|
487
|
+
rejectScopedRepositoryConnectionMutation(ctx);
|
|
488
|
+
}
|
|
489
|
+
} else {
|
|
490
|
+
rejectScopedAssociationMutation(ctx, REPOSITORY_ASSOCIATION_SEGMENTS);
|
|
491
|
+
requireScopedRepositoryValue(ctx, values, scope, actionName);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
await next();
|
|
495
|
+
}
|
|
496
|
+
async function repositoryIdFromSubtreeConfig(ctx, configId) {
|
|
497
|
+
if (!ctx.db) ctx.throw(403, "Permission denied");
|
|
498
|
+
const config = await ctx.db.getRepository("gitSubtreeConfigs").findOne({ filterByTk: configId });
|
|
499
|
+
if (!config) ctx.throw(404, "Subtree configuration not found");
|
|
500
|
+
const repositoryId = asRepositoryId(getRecordValue(config, "repositoryId"));
|
|
501
|
+
if (repositoryId == null) ctx.throw(403, "Permission denied");
|
|
502
|
+
return repositoryId;
|
|
503
|
+
}
|
|
504
|
+
async function repositoryIdFromReview(ctx, reviewId) {
|
|
505
|
+
if (!ctx.db) ctx.throw(403, "Permission denied");
|
|
506
|
+
const review = await ctx.db.getRepository("gitCodeReviews").findOne({ filterByTk: reviewId });
|
|
507
|
+
if (!review) ctx.throw(404, "Review not found");
|
|
508
|
+
const repositoryId = asRepositoryId(getRecordValue(review, "repositoryId"));
|
|
509
|
+
if (repositoryId == null) ctx.throw(403, "Permission denied");
|
|
510
|
+
return repositoryId;
|
|
511
|
+
}
|
|
512
|
+
async function enforceRepositoryAccess(ctx, next) {
|
|
513
|
+
var _a;
|
|
514
|
+
const action = ctx.action;
|
|
515
|
+
const actionName = action == null ? void 0 : action.actionName;
|
|
516
|
+
if ((action == null ? void 0 : action.resourceName) !== "gitManager" || !actionName) {
|
|
517
|
+
return next();
|
|
518
|
+
}
|
|
519
|
+
const currentRoles2 = (_a = ctx.state) == null ? void 0 : _a.currentRoles;
|
|
520
|
+
const roles = Array.isArray(currentRoles2) ? currentRoles2.filter((role) => typeof role === "string") : [];
|
|
521
|
+
if (Array.isArray(currentRoles2) && roles.length !== currentRoles2.length) {
|
|
522
|
+
return ctx.throw(403, "Permission denied");
|
|
523
|
+
}
|
|
524
|
+
const params = getEffectiveActionParams(ctx);
|
|
525
|
+
let repositoryId;
|
|
526
|
+
if (REPOSITORY_ID_ACTIONS.has(actionName)) {
|
|
527
|
+
repositoryId = asRepositoryId(params.repositoryId);
|
|
528
|
+
if (repositoryId == null) return ctx.throw(400, "repositoryId is required");
|
|
529
|
+
} else if (SUBTREE_CONFIG_ACTIONS.has(actionName)) {
|
|
530
|
+
const configId = asRepositoryId(params.configId);
|
|
531
|
+
if (configId == null) return ctx.throw(400, "configId is required");
|
|
532
|
+
repositoryId = await repositoryIdFromSubtreeConfig(ctx, configId);
|
|
533
|
+
} else if (REVIEW_ID_ACTIONS.has(actionName)) {
|
|
534
|
+
const reviewId = asRepositoryId(params.reviewId);
|
|
535
|
+
if (reviewId == null) return ctx.throw(400, "reviewId is required");
|
|
536
|
+
repositoryId = await repositoryIdFromReview(ctx, reviewId);
|
|
537
|
+
} else if (actionName === "pollNow") {
|
|
538
|
+
repositoryId = asRepositoryId(params.repositoryId);
|
|
539
|
+
if (repositoryId == null) {
|
|
540
|
+
const allowed2 = await hasUnrestrictedRepositoryAccess({
|
|
541
|
+
acl: ctx.app.acl,
|
|
542
|
+
roles,
|
|
543
|
+
action: actionName
|
|
544
|
+
});
|
|
545
|
+
if (!allowed2) return ctx.throw(403, "Permission denied");
|
|
546
|
+
return next();
|
|
547
|
+
}
|
|
548
|
+
} else {
|
|
73
549
|
return next();
|
|
74
550
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const roles = Array.isArray((_d = ctx.state) == null ? void 0 : _d.currentRoles) ? ctx.state.currentRoles : [];
|
|
78
|
-
if (roles.includes("root")) return next();
|
|
79
|
-
const permission = await ctx.app.acl.can({
|
|
551
|
+
const allowed = await hasRepositoryAccess({
|
|
552
|
+
acl: ctx.app.acl,
|
|
80
553
|
roles,
|
|
81
|
-
|
|
82
|
-
action:
|
|
554
|
+
repositoryId,
|
|
555
|
+
action: actionName
|
|
83
556
|
});
|
|
84
|
-
if (!
|
|
557
|
+
if (!allowed) {
|
|
85
558
|
return ctx.throw(403, "Permission denied");
|
|
86
559
|
}
|
|
87
560
|
return next();
|
|
88
561
|
}
|
|
89
562
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
563
|
0 && (module.exports = {
|
|
91
|
-
enforceRepositoryAccess
|
|
564
|
+
enforceRepositoryAccess,
|
|
565
|
+
enforceRepositoryCollectionAccess,
|
|
566
|
+
getEffectiveActionParams,
|
|
567
|
+
hasRepositoryAccess,
|
|
568
|
+
resolveRepositoryScope,
|
|
569
|
+
scopeIncludesRepository
|
|
92
570
|
});
|