logo

Database

Javascript Cordova File Manipulation

Description

Detects potential file manipulation vulnerabilities in Cordova applications where user-controlled input is used in file system operations. This could allow attackers to access unauthorized files or directories through path traversal attacks.

Weakness:

027 - Insecure file upload

Category: Access Subversion

Detection Strategy

    Identifies calls to window.resolveLocalFileSystemURL in JavaScript code

    Verifies if the arguments/parameters passed to this function contain user-controlled data

    Reports a vulnerability when user input flows into the file system URL resolution without proper sanitization

Vulnerable code example

function writeFile() {
    // Untrusted input directly from URL parameters
    const path = new URLSearchParams(window.location.search).get("path");
    const content = new URLSearchParams(window.location.search).get("content");

    // Vulnerable: Directly concatenating user input into file path
    const fullPath = cordova.file.dataDirectory + path;
...

✅ Secure code example

function writeFile() {
    // Get input parameters
    const path = new URLSearchParams(window.location.search).get("path");
    const content = new URLSearchParams(window.location.search).get("content");

    // Validate inputs
    if (!path || !content) {
        console.error("Missing required parameters");...