Join our Newsletter — 33% off our NHI Course
Home Glossary Cyber Security Malicious JavaScript
Cyber Security

Malicious JavaScript

← Back to Glossary
By NHI Mgmt Group Updated August 27, 2026 Domain: Cyber Security

Malicious JavaScript is code inserted into a website to perform unauthorized actions in the user’s browser. In formjacking, it quietly intercepts form submissions and sends the captured data elsewhere. Because it runs in the browser context, it can look like normal page behavior unless teams inspect source and script activity carefully.

Expanded Definition

Malicious JavaScript is browser-executed code that a threat actor injects into a legitimate site or front-end dependency to alter page behavior without obvious user-visible compromise. In NHI security, it is most often discussed as a delivery mechanism for formjacking, session theft, and client-side data exfiltration, especially when scripts are loaded from third-party tags, compromised packages, or tampered content pipelines. The core risk is not simply that code is “bad,” but that it runs inside a trusted browser context where it can observe keystrokes, read form fields, and relay data before encryption or after rendering. Guidance varies across vendors on whether malicious JavaScript should be treated as application-layer malware, supply chain compromise, or data exfiltration tooling, but the operational control concern is the same: untrusted script execution in the user session. The most common misapplication is treating client-side scripts as harmless presentation logic, which occurs when teams do not inventory, pin, or continuously inspect what actually executes in production browsers.

For a standards-oriented baseline on risk treatment and monitoring, see the NIST Cybersecurity Framework 2.0.

Examples and Use Cases

Implementing protections against malicious JavaScript rigorously often introduces release friction, requiring organisations to weigh front-end agility against stronger script governance and integrity controls.

  • Formjacking on checkout pages, where injected code captures payment or identity fields and forwards them to an attacker-controlled endpoint.
  • Compromised third-party tags, where a benign analytics or chat script is altered upstream and inherits trust on every page that loads it.
  • Supply chain abuse in package ecosystems, as seen in the Shai Hulud npm malware campaign, where tainted JavaScript can become a vehicle for secrets theft and downstream compromise.
  • Session hijacking via browser-side payloads that read tokens from accessible storage or manipulate requests before they leave the page.
  • Script defacement and hidden beaconing, where the page looks normal but silently loads additional code, sends telemetry, or redirects specific victims.

Defensive programs usually combine content security policy, subresource integrity, dependency review, and runtime monitoring, but no single standard governs this yet across all stacks. For broader governance patterns and NHI exposure management, NHI Mgmt Group’s Ultimate Guide to NHIs is a useful reference point.

Why It Matters in NHI Security

Malicious JavaScript becomes an NHI problem because it often targets the same assets that represent machine trust: API keys exposed in front-end workflows, temporary tokens, embedded credentials, and service integrations that should never be visible to end users. NHI Mgmt Group notes that 79% of organisations have experienced secrets leaks, and 77% of those incidents caused tangible damage, which shows how quickly client-side compromise can translate into credential exposure and lateral abuse. The danger is amplified when organisations store secrets outside dedicated managers, reuse long-lived tokens, or allow broad script execution without strong provenance checks. This is where NHI governance fundamentals and the operational priorities described in Shai Hulud npm malware campaign converge: browser code can become an attack path into machine identities, not just a web nuisance. Organisations typically encounter the consequence only after secrets appear in logs, repos, or downstream incidents, at which point malicious JavaScript is operationally unavoidable to address.

A practical control lens aligns well with the NIST Cybersecurity Framework 2.0, especially around asset visibility, protective safeguards, and anomaly detection.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-02Client-side script abuse often leads to secret exposure and unauthorized NHI access.
NIST CSF 2.0PR.DSMalicious JavaScript undermines data security by intercepting information in the browser.
NIST Zero Trust (SP 800-207)SA-3Zero Trust requires treating browser-delivered code as untrusted until verified.

Inventory browser-exposed secrets and block any script path that can read or transmit them.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on August 27, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org