Summary
Storybook's development server WebSocket handlers for creating and saving stories accept unsanitized input and do not validate the origin of incoming connections.
An attacker who can reach a running dev server can inject malicious paths and content that persist in story files, leading to stored cross-site scripting (XSS) or even remote code execution (RCE) in developer environments.
Affected context
This vulnerability occurs in Storybook's WebSocket-based dev server logic that handles "create story" and "save story" operations during active development.
It is relevant when:
- A developer has a local Storybook dev server running and visits a malicious website, or
- The Storybook dev server is intentionally exposed over a network (e.g., for demos or reviews), making it reachable by unauthenticated users.
The issue does not affect static Storybook production builds, but can impact any environment where the dev server is reachable over HTTP/WebSocket.
Exploit preconditions
- Attack surface:
- WebSocket endpoints exposed by the Storybook dev server responsible for handling story create/save messages.
- Required access:
- For local setups:
- The developer must have the dev server running.
- The developer must visit or be embedded into a malicious site (e.g., via iframe, script, or hidden frame) while the dev server is reachable (often on localhost).
- For publicly exposed dev servers:
- Any unauthenticated attacker who can reach the server endpoint over the network can send crafted WebSocket messages.
- Trigger point:
- Malicious WebSocket messages are sent to the dev server's story creation/update handlers, with crafted values in fields such as
componentFilePath. - Why exploitation is possible:
- The WebSocket implementation does not verify the
Originor otherwise authenticate the client, allowing browsers (and remote clients) to establish connections silently. - The server trusts incoming message data, using unsanitized values directly in file paths or story content generation.
- This combination of missing origin validation (WebSocket hijacking) and unsanitized input (CWE-74 / CWE-79) allows injection of persistent script or code into Storybook artifacts.
Why this happens
At its core, the bug stems from the dev server treating WebSocket messages as trusted, structured commands without validating where they originate or sanitizing their contents.
Two classes of weaknesses interact:
- CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component — The
componentFilePathand related fields are inserted into file system paths or code templates without adequate neutralization, allowing crafted input to influence downstream processing and file generation logic. - CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting) — Story content derived from attacker-controlled data can be saved and later rendered in Storybook's UI, enabling stored XSS when other users or the same developer load those stories.
The absence of WebSocket origin checking further broadens the threat, because it allows arbitrary sites or remote clients to send these malformed messages as if they were legitimate, exploiting the overly permissive design of the dev server's message handlers.
Potential impact
- Persistent XSS in Storybook's UI, where injected scripts execute whenever affected stories are viewed.
- Remote Code Execution (RCE) in the development environment if injected content is interpreted or executed by developer tooling, build steps, or script loaders.
- Unauthorized modification or creation of story files, components, or configuration under the dev server's control.
- Compromise of developer workstations through malicious scripts that exfiltrate credentials, access tokens, or sensitive local data available in the browser context.
- Lateral movement into internal services or repositories if a compromised dev environment holds privileged credentials or network access.
General mitigation guidance
Effective mitigation generally involves a combination of stricter WebSocket security controls and robust input handling patterns:
- Enforce strict WebSocket origin checks:
- Validate the
Originheader against an allowlist of trusted origins. - Reject connections that do not originate from the expected Storybook UI or localhost development pages.
- Require authentication or capability checks for state-changing WebSocket actions:
- Treat WebSocket operations that create or modify files as privileged and protect them with tokens, sessions, or explicit dev-only capabilities.
- Harden input validation and encoding:
- Treat all values such as
componentFilePathand story content as untrusted input. - Apply rigorous validation (e.g., allowed characters, directories, extensions) before using inputs in file paths or code generation.
- Properly encode or escape user-supplied data wherever it may end up in HTML, JavaScript, or configuration to prevent XSS and code injection.
- Constrain file system effects:
- Limit where the dev server can write or modify files to a dedicated workspace, preventing escape into arbitrary paths.
- Avoid directly interpolating user-controlled data into code files without intermediate normalization and review.
- Reduce exposure of dev servers:
- Keep Storybook dev servers bound to localhost by default and avoid exposing them directly to the internet.
- When remote access is required, place dev servers behind VPNs, access controls, or reverse proxies with authentication.
- Run with least privilege:
- Ensure developer tools run with minimal filesystem and OS permissions necessary for development, limiting the blast radius if injections occur.
How teams detect issues like this
Detection efforts can combine code-centric analysis with runtime monitoring:
- Static analysis and code scanning:
- Search for WebSocket handlers that:
- Do not validate
Originor authenticate clients. - Directly trust incoming JSON payload fields for file operations or story generation.
- Flag string concatenation or templating where user-controllable fields (e.g., paths, story bodies) are written to disk or embedded into HTML/JS without escaping.
- Code review practices:
- Review dev tooling and internal web utilities with the same rigor as production code, especially where they write files, execute scripts, or manage dynamic imports.
- Use checklists to ensure WebSocket endpoints:
- Enforce origin checks or authentication.
- Distinguish between read-only and state-changing operations.
- Policy and linting rules:
- Introduce lint rules or internal guidelines that disallow:
- Path construction or code generation from unsanitized external data.
- Unauthenticated, origin-less WebSocket access for privileged operations.
- Runtime and behavioral monitoring (for shared dev infrastructure):
- If dev environments are centralized, log WebSocket message sources, frequency, and payload characteristics to identify unusual activity (e.g., bursts of story creation from unfamiliar IPs).
- Consider integrating with broader security monitoring platforms to detect suspicious file changes or scripts appearing in repositories or story directories.
- Automated tooling:
- Use application security testing tools (DAST/IAST) where feasible to probe dev endpoints in staging environments and identify missing origin checks and injection sinks earlier in the lifecycle.

