Code RoomFile serve with path check
HardPrep Room Coding #2073

File serve with path check

Code reviewCode quality & reviewSenior–Staff~24 min

Review this Java file-serving endpoint that already normalizes and prefix-checks the path.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 24 min
Mark a line and say what kind of problem it is.0 findings
1File serve(String name) throws IOException {
2 File base = new File("/srv/files");
3 File target = new File(base, name).getCanonicalFile();
4 if (!target.getPath().startsWith(base.getCanonicalPath())) {
5 throw new SecurityException("escape");
6 }
7 return target; // streamed to the client
8}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.