

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Principle of Least Privilege
incomplete
2: Preventing Broken Access Control
incomplete
3: Don't Trust the Client
incomplete
4: Access Control Models
incomplete
5: Attribute-Based Access Control
incomplete
6: RBAC vs. ABAC
incomplete
7: Insecure Direct Object References
incomplete
8: Securing File Downloads
incomplete
9: Signed URLs
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
A protected file presents an easy-to-overlook authorization problem. Many file servers map URL paths to files, and if the server doesn't check that the requester is allowed to access a file, any authenticated user can download another user's file by changing the URL.
The simplest solution is often to avoid exposing the file directly. Instead, the server checks permission and then streams the file to the authorized user.
file, found, err := store.FindByID(request.Context(), fileID)
if err != nil {
return err
}
if !found || (file.UserID != current.User.ID && current.User.Role != "support" && current.User.Role != "admin") {
respondNotFound(responseWriter)
return nil
}
serveDocument(responseWriter, request, file.OriginalName, file.ContentType, file.StoragePath)
Sending a file with Go's net/http package does not decide who should receive it. The authorization check needs to happen before the handler streams the file.
The storage path should also come from trusted server-side metadata, not directly from a URL parameter. Treat the URL's file ID as an untrusted reference, then resolve it through a database or other server-side mapping.
A secure direct-download flow follows one guarded path:
Bearly Secure lets any authenticated user download any tax-exemption document by changing the file ID. Secure the download route while preserving legitimate customer, support, and administrator access.
With Bearly Secure still running, run and submit the CLI tests from the project root.