Secure code review

Reviewing application file storage and execution boundaries

Protected storage: document, database, key arranged to illustrate reviewing application file storage and execution boundaries.

File handling combines user permissions with content interpretation, storage paths and later retrieval. Understanding application file storage and execution boundaries helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Storage security concerns the copies that remain after an operation has finished. Files, databases, caches and exports can have different access rules and retention periods. A protected main database does not automatically protect a temporary copy or a restored backup.

This section includes requirements to prevent files from being inappropriately executed after upload, to detect dangerous content, and to avoid untrusted data being used to control where files are being stored.

Why it matters

Consider a realistic failure: an ordinary uploaded document crosses into an executable or broadly accessible location during processing.

Exposure can involve private records, reusable credentials or information that identifies a customer. The practical impact depends on which copy is accessible, the access an attacker needs and whether the recovered material remains useful.

A code audit connects a stated requirement to the implementation responsible for enforcing it. Source review and targeted behavioural checks should explain the same boundary and any relevant exceptions.

How penetration testers check for it

Review the specific control expectations below against the code, deployment and observable application behaviour.

  • Confirm that files uploaded or generated by untrusted input and stored in a public folder, are not executed as server-side program code when accessed directly with an HTTP request.
  • Confirm that when the application creates file paths for file operations, instead of user-submitted filenames, it uses internally generated or trusted data, or if user-submitted filenames or file metadata must be used, strict validation and sanitization must be applied. This is to protect against path traversal, local or remote file inclusion (LFI, RFI), and server-side request forgery (SSRF) attacks.
  • Confirm that server-side file processing, such as file decompression, ignores user-provided path information to prevent vulnerabilities such as zip slip.
  • Check temporary copies, exports, backups and deletion behaviour.
  • Establish whether recovered information grants any further access.

How to fix it

Implement the required boundary in the component that actually performs the sensitive operation and retain focused regression coverage.

  • Retain only the information needed for the service.
  • Separate private working data from deliberately shared content.
  • Protect encryption keys independently of encrypted files.
  • Verify removal and recovery behaviour against the intended lifecycle.

Encryption is one part of the design. It cannot compensate for an application that willingly returns plaintext to an unauthorised caller.

Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.

Read about our methodology or contact pentested.com to discuss the security of your application code.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo