-
1. Threat: Malicious Third-Party Plugin (Native API Access)
- Description: An attacker publishes a seemingly legitimate uni-app plugin on a public repository (e.g., the official plugin market or npm). This plugin claims to provide useful functionality but contains hidden malicious code. The malicious code uses the
uni.
API to access native device features (e.g.,uni.getCamera
,uni.getLocation
,uni.getFileSystemManager
) without the user's explicit consent or knowledge, or it abuses granted permissions. - Impact:
- Silent recording of audio or video.
- Tracking the user's location.
- Accessing and exfiltrating contacts, photos, or other sensitive data stored on the device or accessible via granted permissions.
- Sending SMS messages or making phone calls without the user's knowledge.
- Reading/writing files on the device's file system without authorization.
- Affected Component: The malicious third-party plugin itself, and any
uni.
API calls it makes to access native device features or interact with the file system. Specifically, any plugin using native bridging capabilities. - Risk Severity: High
- Mitigation Strategies:
- Developer:
- Thoroughly vet any third-party plugins before integrating them. Examine the source code (if available), check the developer's reputation, and look for red flags (excessive permissions, obfuscated code, lack of documentation).
- Use only plugins from trusted sources (official uni-app plugin market, well-known developers with a strong security track record).
- Implement a "least privilege" approach, granting plugins only the minimum necessary permissions. Carefully review the plugin's manifest/documentation to understand its permission requirements.
- Regularly update all plugins to their latest versions to patch any discovered vulnerabilities.
- Consider sandboxing plugins (if technically feasible and you have the expertise) to limit their access to the rest of the application and the device.
- Monitor plugin behavior at runtime (if possible) for suspicious activity.
- Developer:
- Description: An attacker publishes a seemingly legitimate uni-app plugin on a public repository (e.g., the official plugin market or npm). This plugin claims to provide useful functionality but contains hidden malicious code. The malicious code uses the
-
2. Threat: Insecure Data Storage using
uni.setStorage
(Unencrypted Sensitive Data)- Description: A developer uses
uni.setStorage
oruni.setStorageSync
to store sensitive user data (API keys, session tokens, personally identifiable information (PII), authentication secrets) without encrypting the data. An attacker who gains access to the device's storage (through another app vulnerability, physical access, or a compromised backup) can easily retrieve this unencrypted data. - Impact:
- Compromise of user accounts (leading to unauthorized access to services).
- Identity theft.
- Financial loss (if financial data is stored).
- Exposure of sensitive personal information, potentially leading to privacy violations or reputational damage.
- Affected Component: The
uni.setStorage
anduni.getStorage
(and their synchronous counterparts) APIs. - Risk Severity: High
- Mitigation Strategies:
- Developer:
- Never store sensitive data unencrypted using
uni.setStorage
. This is a fundamental security principle. - Use a strong, well-vetted encryption library (e.g., CryptoJS, a native cryptography plugin) to encrypt sensitive data before storing it with
uni.setStorage
. - Use a securely generated and securely stored encryption key. Do not hardcode the key.
- Implement a robust key management system. Consider using platform-specific secure storage mechanisms (Android Keystore, iOS Keychain) for the encryption key itself, accessed via a uni-app plugin or native bridge code. This adds a layer of protection.
- Consider using a key derivation function (KDF) to derive the encryption key from a user-provided password or other secret, rather than storing the key directly.
- Never store sensitive data unencrypted using
- Developer:
- Description: A developer uses
-
3. Threat: Unsafe Use of
eval
in a Custom Component- Description: A developer uses the
eval()
function (or similar dynamic code execution mechanisms likeFunction()
) within a custom uni-app component. The input toeval()
is, even partially, derived from user-provided data or an untrusted source, and proper sanitization is either missing or insufficient. An attacker crafts malicious input that includes JavaScript code, which is then executed byeval()
. - Impact:
- Execution of arbitrary JavaScript code within the application's context, giving the attacker significant control.
- Potential access to sensitive data stored within the application's scope or accessible via the
uni.
API. - Redirection of the user to malicious websites (phishing).
- Defacement of the application's UI.
- Potential for cross-site scripting (XSS) attacks if the executed code interacts with the DOM.
- Affected Component: The custom component that uses the
eval()
function (orFunction()
), and potentially any other part of the application that interacts with this component or its output. - Risk Severity: Critical
- Mitigation Strategies:
- Developer:
- Avoid
eval()
andFunction()
entirely. This is the most important mitigation. There are almost always safer alternatives to achieve the desired functionality without resorting to dynamic code execution. Explore alternative design patterns and libraries. - If, in an extremely rare and exceptional case,
eval()
is deemed absolutely unavoidable (and this should be heavily scrutinized and justified), implement extremely strict input validation and sanitization. Use a whitelist approach, allowing only a very limited and well-defined set of characters and patterns. This is still a very high-risk approach and should be a last resort, accompanied by extensive security review. - Use a Content Security Policy (CSP) to restrict the execution of inline scripts, providing an additional layer of defense even if the
eval()
-based protection is bypassed.
- Avoid
- Developer:
- Description: A developer uses the
-
4. Threat: Insecure Network Requests via
uni.request
(Missing or Weak HTTPS)- Description: A developer uses
uni.request
to communicate with a backend server, but fails to enforce HTTPS, uses an outdated or misconfigured HTTPS setup (weak ciphers, expired certificates), or does not implement certificate pinning. An attacker on the same network (e.g., public Wi-Fi) or a compromised network infrastructure component can perform a man-in-the-middle (MITM) attack. - Impact:
- Interception of sensitive data transmitted between the app and the server (user credentials, API keys, personal data).
- Modification of data sent to or received from the server, potentially leading to data corruption or malicious actions.
- Injection of malicious content into the application, potentially leading to further compromise.
- Affected Component: The
uni.request
API. - Risk Severity: High
- Mitigation Strategies:
- Developer:
- Always use HTTPS for all network requests made with
uni.request
. Ensure the server has a valid, trusted SSL/TLS certificate. - Implement certificate pinning. This prevents MITM attacks even if a certificate authority is compromised. uni-app provides mechanisms for this.
- Use strong, modern cipher suites and TLS versions on the server.
- Validate server responses to ensure they haven't been tampered with (e.g., check checksums or digital signatures if applicable).
- Regularly update the server's SSL/TLS certificates and keep the server software up-to-date.
- Always use HTTPS for all network requests made with
- Developer:
- Description: A developer uses