Skip to content
Ameen Abozaid
Planned lessonJNR-023-L05

Upload security

  • Lesson 5 of 6
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

name the main upload risks.

Planned topics

  • Path traversal: a name like ../../etc/passwd escapes the folder. Prevent it by never using the client name in a path; if you must resolve a path, normalize() it and check it stays inside the base directory.
  • Oversized files: exhaust disk or memory. Enforce limits.
  • Content sniffing: a browser may guess a type and run a file as script. Send the right Content-Type, and X-Content-Type-Options: nosniff.
  • Trusting the declared type: verify signatures for important types.
  • Serve uploads only through your controller, with access checks.
Draft outline details

Demonstration

java
Path target = base.resolve(storedName).normalize();
if (!target.startsWith(base)) throw new IllegalArgumentException("Bad path");

Check your understanding

Which input should never be part of a path?

Show answer

The client's filename.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.