Summary
A critical code injection vulnerability in Bilibili Desktop may allow a remote attacker to execute arbitrary code through the bili-inject.js and bili-bridge.js components. The risk arises when attacker-controlled input reaches these components without adequate validation, isolation, or execution controls.
Affected context
The issue occurs in Bilibili Desktop deployments using the bili-inject.js and bili-bridge.js components. Exploitation depends on a reachable application interaction or message path that permits attacker-controlled data to be processed as executable code; the available description does not establish the exact delivery mechanism or required user interaction.
Exploit preconditions
- Attack surface: Remote application functionality involving the affected JavaScript components
- Required access: Ability to reach the relevant desktop application interaction or communication path
- Trigger point: Processing of attacker-controlled input by bili-inject.js or bili-bridge.js
- Why exploitation is possible: Input may be interpreted as code rather than treated strictly as data
Why this happens
The underlying bug is an unsafe code-generation or code-execution pattern in which externally influenced data can reach a JavaScript execution context. When input is not constrained to an expected data format and is instead interpreted dynamically, an attacker may influence program behavior or cause arbitrary code to run. This behavior maps to CWE-94, Improper Control of Generation of Code.
Potential impact
- An attacker may execute arbitrary code with the privileges of the desktop application
- Local files or application data could be accessed or modified
- Credentials, session information, or other sensitive data may be exposed
- The affected workstation could be used for persistence, malware deployment, or lateral movement
General mitigation guidance
Mitigation generally focuses on ensuring that untrusted input remains data and
cannot become executable JavaScript.
Common defensive patterns include:
- Replacing dynamic evaluation and runtime code generation with fixed program logic
- Applying strict allowlists and schema validation to messages and bridge arguments
- Separating privileged operations from content-rendering or injection contexts
- Enforcing strong context-specific output encoding and safe API boundaries
- Limiting desktop application privileges and isolating high-risk renderer or bridge components
- Restricting exposed bridge methods to the smallest required interface
- Using secure-by-default content security and process-isolation controls
How teams detect issues like this
Detection approaches may include:
- Static analysis rules for eval-like APIs, dynamic function construction, string-based script execution, and unsafe bridge exposure
- Code review checks for renderer-to-main communication that accepts arbitrary commands or unvalidated arguments
- Searches for JavaScript injection sinks receiving network, IPC, URL, or document-derived data
- Runtime monitoring of unexpected child-process creation, script loading, or filesystem and credential access by the desktop application
- Policy enforcement requiring schema validation, least-privilege bridge design, and security review for privileged JavaScript interfaces
Automated security scanning and code review tools may help identify these patterns during development.

