← Back to Baseline

MB-0787

Automated No unconditional validateForCsrf acceptance override

MB-C03 Secure Coding Practices Medium

Collected custom PHP/PHTML contains no validateForCsrf method whose complete body is an unconditional return true. This exact bypass ban does not establish form tokens or server-side CSRF effectiveness. Scope is completely collected app/code PHP/PHTML; missing, unreadable, oversized, linked, malformed or truncated eligible input prevents a clean PASS.

Overview

Collected custom PHP/PHTML contains no validateForCsrf method whose complete body is an unconditional return true. This exact bypass ban does not establish form tokens or server-side CSRF effectiveness. Scope is completely collected app/code PHP/PHTML; missing, unreadable, oversized, linked, malformed or truncated eligible input prevents a clean PASS.

Why it Matters

An unconditional positive CSRF decision can silently bypass a controller's intended request protection. Finding the exact method shape makes this specific exception visible.

Removing that exception is only part of validating a real form/token workflow.

Verification Steps

Manual Verification

  1. Inventory validateForCsrf methods in collected app/code PHP/PHTML.
  2. Inspect complete method bodies and reject the exact unconditional true implementation.
  3. Trace inherited/delegated behavior and test actual token enforcement separately.

Command / Review Sample

// Pattern to review:
public function validateForCsrf(...) { return true; }
// Check the complete method, not a comment or string containing this text.

Use the assessed Magento project and the appropriate application or read-only review account. Replace example hosts, paths and identifiers with the assessment scope; configuration and source fragments are illustrative.

Remediation / Fix Guidance

  1. Remove the unconditional true validateForCsrf override. Delegate to Magento validation where appropriate, or implement and test the provider-specific alternate request authentication before accepting a deliberately exempt callback. Do not merely rename the method or add an unused form-key helper.
  2. In isolation, verify missing, invalid and foreign-session tokens cannot perform the protected state change; check valid requests and any authenticated webhook exception still work.
  3. Rerun MB-0787 against the same release, profile and relevant file/key/package scope; compare the new evidence and inspect any independent collection gaps.

Examples

Illustrative examples only. Interpret them within the current revision criterion above; missing collection evidence is unresolved, never PASS.

Fail Example

public function validateForCsrf(RequestInterface $request): ?bool
{
    return true;
}

Pass Example

public function validateForCsrf(RequestInterface $request): ?bool
{
    return null; // Defer to the framework's normal validation.
}
// Independently test actual CSRF enforcement.

Scope and Evidence Limits

Rule revision: 1. Target modes: LOCAL.

Collected custom PHP/PHTML contains no validateForCsrf method whose complete body is an unconditional return true. This exact bypass ban does not establish form tokens or server-side CSRF effectiveness. Scope is completely collected app/code PHP/PHTML; missing, unreadable, oversized, linked, malformed or truncated eligible input prevents a clean PASS.

Exact opt-in coding policy, not a finding of confirmed exploitability or proof of the broader historical requirement. Runtime adapters, dependencies, generated code and files outside app/code remain outside this predicate.

Catalog coverage describes implementation capability, not a scan outcome. An incomplete manual review cannot establish that the criterion is satisfied.

References