Dynamic code delivery is a pattern where a service generates or changes code responses at request time based on headers, device type, or other runtime signals. This flexibility can improve compatibility, but it also creates an attack surface when adversaries can alter the delivered payload or conditionally trigger malicious behaviour.
What Dynamic Code Delivery Means in Practice
Dynamic code delivery is not just “responsive content.” It is a runtime decision path that changes executable or interpretable payloads after the request arrives, often using headers, device signals, locale, or client capabilities to decide what code is sent.
The core security issue is that the delivery logic becomes part of the trust boundary. If the signal used to choose the payload can be influenced, the system may serve code that is inconsistent with the intended security posture, compatibility expectations, or review assumptions.
Why It Exists and Where It Is Used
Teams use dynamic code delivery to reduce friction across browsers, devices, network conditions, or feature sets. The same pattern can support progressive enhancement, A/B testing, feature flags, or conditional loading of scripts and components.
That flexibility is useful, but it also means the delivered code is no longer a single static artifact. Different users, sessions, or request paths may receive materially different logic, which makes governance, testing, and reproducibility harder.
Security Properties and Failure Modes
From a security perspective, dynamic code delivery matters because the payload itself may change based on request metadata, and those inputs are often easier to spoof than defenders assume. If attackers can manipulate headers, user agent values, routing conditions, or other runtime signals, they may influence which code path is executed or exposed.
This can create integrity issues such as unsafe script selection, hidden malicious branches, inconsistent client-side protections, or payloads that bypass review because they only appear under specific conditions. The risk is not just malicious code injection, but also conditional behaviour that is difficult to detect in normal testing.
Operational Implications for Review and Control
Dynamic delivery requires stronger assurance than a one-time code review of the source artifact. Security teams need to understand which request attributes control the response, whether those attributes are authenticated or merely informational, and whether the runtime decision can be forced into an unsafe state.
It also changes how monitoring works. Static analysis alone may miss code that is only emitted under certain headers or device profiles, so validation needs to account for the actual decision tree that determines what gets delivered and when.
Risk and Threat Considerations
Dynamic code delivery expands the attack surface because the response can vary by request context, and that context is often attacker-influenced. The biggest concern is conditional malicious behaviour: code that looks normal in one path but becomes unsafe when a specific header, device type, or feature flag is present.
Failure mechanism: An attacker manipulates runtime signals or intermediary behaviour so the service selects a different payload, bypasses a safety check, or emits code that was not intended for that execution path.
Impact: The result can be client-side compromise, integrity loss, hidden execution paths, inconsistent enforcement, or exposure of users to code that defenders did not meaningfully review under the affected conditions.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP API Security Top 10 and MITRE ATT&CK address the attack and risk surface, while OWASP ASVS sets the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V15 — Secure Coding and Architecture | Dynamic delivery changes executable behaviour at runtime and needs secure design review. |
| V13 — Configuration | Request-driven delivery often depends on configuration and feature routing decisions. | |
| V16 — Security Logging and Error Handling | Conditional payload selection needs detection and traceability when different code paths are served. | |
| Recommendation — Review runtime code-selection logic for unsafe branches and ensure security-sensitive behaviour is explicitly designed and tested. Validate configuration paths that decide which code is emitted so attackers cannot steer them into unsafe states. Log code-selection decisions and anomalous runtime conditions so unusual delivery paths are detectable. | ||
| OWASP API Security Top 10 | API8 — Security Misconfiguration | Runtime code variation can emerge from weak request handling or unsafe environment assumptions. |
| Recommendation — Harden request parsing and routing so delivery logic cannot be altered through misconfiguration or unsafe defaults. | ||
| MITRE ATT&CK | T1190 — Exploit Public-Facing Application | Attackers can abuse exposed request logic that alters delivered code or activates unsafe paths. |
| Recommendation — Map exposed delivery controls to public-facing application abuse paths and test them with malicious request inputs. | ||
Practitioner Guidance
What to watch for: Treat request-controlled selection logic as part of the security boundary, not a convenience feature. The most important question is whether the system can be pushed into serving materially different code by inputs the attacker can influence.
Governance implication: Document which signals are trusted, which are advisory, and which code paths are security-sensitive. Dynamic delivery should be reviewed with the same discipline as any other mechanism that changes executable behaviour at runtime.
Related resources from NHI Mgmt Group
- How should teams close Infrastructure as Code skills gaps without slowing delivery?
- How can organisations make code review more trustworthy without slowing delivery?
- How do security teams detect malicious software delivery when the code looks legitimate?
- Who is accountable when an abused code-signing certificate enables malware delivery?