MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / validatePolicy

Function validatePolicy

packages/cli/src/commands/lambda/policies.ts:311–379  ·  view source on GitHub ↗
(policyPath: string)

Source from the content-addressed store, hash-verified

309 * not by our matcher. We end-anchor only.
310 */
311export function validatePolicy(policyPath: string): ValidateResult {
312 const raw = readFileSync(policyPath, "utf-8");
313 const parsed = JSON.parse(raw) as { Statement?: unknown };
314 const statements: Array<{
315 Effect?: string;
316 Action?: unknown;
317 NotAction?: unknown;
318 NotResource?: unknown;
319 }> = Array.isArray(parsed.Statement)
320 ? (parsed.Statement as {
321 Effect?: string;
322 Action?: unknown;
323 NotAction?: unknown;
324 NotResource?: unknown;
325 }[])
326 : parsed.Statement
327 ? [
328 parsed.Statement as {
329 Effect?: string;
330 Action?: unknown;
331 NotAction?: unknown;
332 NotResource?: unknown;
333 },
334 ]
335 : [];
336
337 const grantedPatterns: string[] = [];
338 const warnings: string[] = [];
339 for (const stmt of statements) {
340 if (stmt.Effect !== "Allow") continue;
341 if (stmt.NotAction !== undefined) {
342 warnings.push(
343 "Allow statement uses NotAction; the validator only checks positive Action grants, so this statement is being ignored. Convert to an explicit Action list to validate it.",
344 );
345 continue;
346 }
347 if (stmt.NotResource !== undefined) {
348 warnings.push(
349 "Allow statement uses NotResource; resource-scoping is not modelled by this validator. Treating the statement as fully granted on its Action set.",
350 );
351 }
352 const actions = stmt.Action;
353 if (typeof actions === "string") {
354 grantedPatterns.push(actions);
355 } else if (Array.isArray(actions)) {
356 for (const a of actions) if (typeof a === "string") grantedPatterns.push(a);
357 }
358 }
359
360 for (const pattern of grantedPatterns) {
361 if (hasMidStringWildcard(pattern)) {
362 warnings.push(
363 `Action pattern ${JSON.stringify(pattern)} contains a mid-string wildcard the validator can't expand; only end-anchored wildcards (\`*\`, \`service:*\`, \`prefix*\`) are honoured.`,
364 );
365 }
366 }
367
368 const required = allRequiredActions();

Callers 2

runPoliciesFunction · 0.85
policies.test.tsFile · 0.85

Calls 3

hasMidStringWildcardFunction · 0.85
allRequiredActionsFunction · 0.85
actionMatchesFunction · 0.85

Tested by

no test coverage detected