in src/policy.ts [109:137]
export async function localPolicyAssessment(context: RecaptchaContext, req: EdgeRequest): Promise<LocalAssessment> {
// Optimization to inspect a cached copy of the firewall policies if HTTP caching is enabled.
let resp;
try {
context.log_performance_debug("[rpc] callListFirewallPolicies - start");
resp = await callListFirewallPolicies(context);
context.log_performance_debug("[rpc] callListFirewallPolicies - end");
} catch (reason) {
context.logException(reason);
return "recaptcha-required";
}
const policies = resp.firewallPolicies ?? [];
for (const policy of policies) {
if (policyPathMatch(policy, req)) {
const conditionMatch = policyConditionMatch(policy, req);
if (conditionMatch === "unknown") {
return "recaptcha-required";
} else if (conditionMatch) {
// TODO: handle multiple policies.
context.log_performance_debug("conditionMatch");
context.log("debug", "local assessment condition matched");
return policy?.actions ?? [];
}
}
}
context.log_performance_debug("no conditionMatch");
// No policies were found to match in the cache. This default to 'allow'.
return [action.createAllowAction()];
}