Dynamic class loading is the runtime loading of a software class into a program after the application has started. It is used in languages and platforms that resolve classes on demand, often through reflection, plug-ins, or custom class loaders, which changes what code is available at execution time and can affect control over behaviour and trust.
How dynamic class loading works
Dynamic class loading means the application decides at runtime which code to load and initialise, rather than having every class fixed and resolved at startup. That makes the runtime behaviour more flexible, but it also means the effective code path can change based on configuration, input, plug-in discovery, reflection, or a custom loader.
In practice, the class loader becomes part of the trust boundary. If the application can be influenced to load an unexpected class, it may execute code that was never intended for that context, which is why this pattern sits at the intersection of extensibility and execution control.
Why it is used
Teams use dynamic loading to support plug-in architectures, modular applications, late binding of dependencies, and platform features that need to discover capabilities at runtime. It is common in ecosystems where optional components should be activated only when present, or where the same binary must run across different deployments with different extension sets.
The benefit is adaptability. The trade-off is that security review can no longer rely only on a static dependency graph, because some execution paths are only visible once the application is live and the loader has made its decisions.
Security implications of runtime code loading
Dynamic loading affects trust, integrity, and control over execution. If an attacker can place, replace, or steer a class that the application will accept, the result can be arbitrary code execution, unsafe plug-in behaviour, or escalation through code running with the application's own privileges. This is especially sensitive where loaders search writable paths, accept user-controlled class names, or resolve modules from untrusted sources.
It also complicates assurance. Security teams need to know which code can actually execute, not just which code ships in the artefact. NIST Cybersecurity Framework 2.0 is useful here because the issue spans govern, identify, protect, detect, respond, and recover functions around runtime trust decisions.
Detection and control points
Controls usually focus on constraining what can be loaded, where it can come from, and how much privilege the loaded code receives. Strong class loading design treats plug-in sources as managed inputs, not as automatically trusted extensions. Logging the resolved class name, source location, and loading context also helps investigators reconstruct what ran after an incident.
For broader hardening around code execution paths, NIST Privacy Framework is not the primary reference for class loading itself, but it can support governance where runtime extensibility changes what data the application may expose or process. NIST SP 800-53 Rev 5 Security and Privacy Controls is the more direct control catalogue for access control, configuration management, and logging safeguards around this kind of runtime behaviour.
Where the risk is highest
Risk rises when dynamic loading is paired with untrusted extension points, weak package signing, permissive class-path handling, or poor segregation between core application logic and third-party modules. It also grows when the loaded code can reach sensitive APIs, secrets, administrative functions, or internal service boundaries without an additional authorisation check.
Because the loader decides what code becomes active, failures here can bypass assumptions made during development, code review, and software composition analysis. That is why runtime extensibility should be treated as an execution-control problem, not just a packaging feature.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
MITRE ATT&CK addresses the attack and risk surface, while NIST CSF 2.0 and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST CSF 2.0 | GV.RM-01 — Risk Management Strategy | Dynamic loading changes runtime trust and execution risk management. |
| Recommendation — Define approval and review rules for runtime-loaded code paths. | ||
| NIST SP 800-53 Rev 5 | CM-5 — Access Restrictions for Change | Controls who can alter code paths and runtime loading sources. |
| CM-7 — Least Functionality | Limit executable components to the minimum needed at runtime. | |
| AU-2 — Event Logging | Runtime class resolution needs auditability for investigation. | |
| Recommendation — Restrict who can modify loaders, plug-in sources, and deployment paths. Disable unnecessary dynamic loading and remove unused extension points. Log loaded class names, sources, and resolution decisions. | ||
| MITRE ATT&CK | T1574 — Hijack Execution Flow | Abuse of runtime loading can redirect execution to attacker code. |
| Recommendation — Hunt for hijacked execution paths and unexpected load order changes. | ||
Practitioner Guidance
Governance implication: Treat every dynamic loading path as an approved extension mechanism with defined ownership, source trust, and review criteria. Do not let class names, module identifiers, or plug-in locations come from uncontrolled input unless the application strictly validates them against an allowlist.
What to watch for: Unexpected loader destinations, writable plug-in directories, and classes appearing at runtime from locations that are not part of the intended release artefact are all signals that the trust model needs review. MITRE ATT&CK Enterprise Matrix is useful for mapping how attacker-controlled code execution can support persistence, privilege escalation, and lateral movement once a malicious class is loaded.
Related resources from NHI Mgmt Group
- What is the difference between remote class loading and unsafe object factory execution in JNDI attacks?
- Why do obfuscation, dynamic code loading, and encrypted payloads make Android malware harder to assess?
- When does dynamic tool use create more value than direct MCP tool loading?
- What is the difference between direct MCP tool loading and dynamic tool use?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 3, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org