← Back to Baseline

MB-0736

Automated Supported inline JavaScript output uses context-appropriate escaping

MB-C03 Secure Coding Practices High

Within bounded collected templates, supported direct PHP output into inline JavaScript calls recognized JS-string escaping APIs or supported native JSON encoding in the appropriate supported context. This is a syntax observation; unresolved receiver/function identity, dynamic markup, unsupported JS contexts and incomplete coverage remain unavailable, not proof of browser-wide safety.

Overview

Within bounded collected templates, supported direct PHP output into inline JavaScript calls recognized JS-string escaping APIs or supported native JSON encoding in the appropriate supported context. This is a syntax observation; unresolved receiver/function identity, dynamic markup, unsupported JS contexts and incomplete coverage remain unavailable, not proof of browser-wide safety.

Why it Matters

Context-matched encoding helps prevent dynamic data from changing the intended output syntax. Review supported receivers, APIs and embedding contexts together.

The check observes supported syntax only. A recognized call cannot establish safe custom implementations, all dynamic markup or complete runtime XSS protection.

Verification Steps

Manual Verification

  1. Review supported template receivers and context-matched escaping syntax only. Unsupported contexts or receiver/function identities remain unavailable; syntax is not proof of runtime XSS safety.
  2. Review inline scripts, event handlers and JSON embedding.
  3. Trace dynamic values to context-appropriate serialization and avoid string concatenation into executable script.
  4. Test quotes and delimiters using inert fixtures.

Command / Review Sample

# Data serialization illustration; HTML embedding needs appropriate flags/context:
$json = json_encode($value, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);

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. Use JS-string escaping or the supported encoding form for the actual inline JavaScript output; review unsupported browser contexts separately.
  2. Validate the exact named inputs and supported scope used by the finding; resolve unavailable data before interpreting a clean result.
  3. Rerun MB-0736 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

A label is concatenated unencoded inside a quoted JavaScript literal.

Pass Example

Dynamic script data is serialized for its exact embedding context without becoming executable syntax.

Scope and Evidence Limits

Rule revision: 2. Target modes: LOCAL.

Within bounded collected templates, supported direct PHP output into inline JavaScript calls recognized JS-string escaping APIs or supported native JSON encoding in the appropriate supported context. This is a syntax observation; unresolved receiver/function identity, dynamic markup, unsupported JS contexts and incomplete coverage remain unavailable, not proof of browser-wide safety.

Within bounded collected templates, supported direct PHP output into inline JavaScript calls recognized JS-string escaping APIs or supported native JSON encoding in the appropriate supported context. This is a syntax observation; unresolved receiver/function identity, dynamic markup, unsupported JS contexts and incomplete coverage remain unavailable, not proof of browser-wide safety.

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

References