logo

Database

Typescript Cordova File Manipulation

Description

Detects unsafe Cordova file system operations in TypeScript applications where user-controlled input is used in file operations. This could allow attackers to manipulate file system paths, potentially leading to unauthorized file access or path traversal attacks.

Weakness:

027 - Insecure file upload

Category: Access Subversion

Detection Strategy

    Check for calls to window.resolveLocalFileSystemURL in the application code

    Verify if any parameters passed to these file system calls contain user-controlled input

    Report a vulnerability if user input flows into the file system operation without proper validation

Vulnerable code example

// Minimal example of file path traversal in Cordova file operations
declare const cordova: { file: { dataDirectory: string } };

function writeUserFile(): void {
    // Vulnerable: Unvalidated path from URL parameters directly used in file path
    const path = new URLSearchParams(window.location.search).get("path");
    const content = new URLSearchParams(window.location.search).get("content");
    ...

✅ Secure code example

// Secure version of file writing in Cordova
declare const cordova: { file: { dataDirectory: string } };

function writeUserFile(): void {
    const path = new URLSearchParams(window.location.search).get("path");
    const content = new URLSearchParams(window.location.search).get("content");
    
    // Sanitize filename by only allowing alphanumeric + extension...