Skip to content

[Backend] Prevent ZIP Path Traversal (Zip Slip) in /scan #332

Description

@arpit2006

Description

The /scan endpoint extracts user-uploaded ZIP archives before scanning their contents. Currently, archive entries are extracted without validating their destination paths, making the endpoint vulnerable to Zip Slip attacks. A malicious archive containing paths such as ../ or absolute paths could write files outside the intended workspace, potentially overwriting sensitive files on the server.

To mitigate this, validate every archive entry before extraction and ensure it resolves within the scan's workspace directory.

Acceptance Criteria

  • Validate each ZIP entry before extraction by resolving its destination path.
  • Ensure every extracted path remains inside the job workspace directory.
  • Skip and log any unsafe entries as WARNING instead of aborting the scan.
  • Continue processing all remaining safe files.
  • If no safe files remain after filtering, return:
    {
      "error": "No safe files found in archive"
    }
    with HTTP 400 Bad Request.
  • Add a unit test using a crafted ZIP archive containing:
    • one safe file (successfully extracted)
    • one path traversal entry (rejected)
  • Verify the safe file is extracted while the malicious entry is ignored.

Why This Matters

Zip Slip is a well-known archive extraction vulnerability that can allow attackers to write files outside the intended extraction directory. Validating extraction paths ensures uploaded archives cannot overwrite arbitrary files on the host system while still allowing legitimate scan requests to proceed.

Difficulty: Medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions