fix: resolve validation and artifact edge cases

This commit is contained in:
N0zoM1z0
2026-07-14 16:15:24 +08:00
parent 6a3fd5b4ce
commit ef7f2f9374
9 changed files with 138 additions and 67 deletions
+35
View File
@@ -0,0 +1,35 @@
/** Structural limits applied while traversing an unknown JSON value. */
export interface JsonLimits {
readonly maxDepth: number;
readonly maxStringLength: number;
readonly maxNodes: number;
}
/** Return whether every node, key, and string fits within the supplied limits. */
export const isJsonWithinLimits = (
root: unknown,
limits: JsonLimits,
): boolean => {
const pending: Array<{ readonly value: unknown; readonly depth: number }> = [
{ value: root, depth: 0 },
];
let nodes = 0;
while (pending.length > 0) {
const current = pending.pop();
if (current === undefined) break;
nodes += 1;
if (nodes > limits.maxNodes || current.depth > limits.maxDepth)
return false;
if (
typeof current.value === "string" &&
current.value.length > limits.maxStringLength
)
return false;
if (typeof current.value !== "object" || current.value === null) continue;
for (const [key, value] of Object.entries(current.value)) {
if (key.length > limits.maxStringLength) return false;
pending.push({ value, depth: current.depth + 1 });
}
}
return true;
};
+1 -4
View File
@@ -165,10 +165,7 @@ export const evaluatePermission = (
reason:
coveringGrant !== undefined && isExpired(coveringGrant, now)
? "grant_expired"
: candidates.length === 0 &&
policy.grants.some(
(grant) => grant.capability === normalized.capability,
)
: coveringGrant !== undefined
? "grant_revoked_or_consumed"
: "grant_required",
missing: missingFromScopes(normalized, candidates),