fix: require auth token for PDF download endpoint (#1428) - #1487
Open
monanksojitra wants to merge 1 commit into
Open
fix: require auth token for PDF download endpoint (#1428)#1487monanksojitra wants to merge 1 commit into
monanksojitra wants to merge 1 commit into
Conversation
The /download route was mounted without the isValidAuthToken middleware, allowing anyone to download any invoice, quote or payment PDF by guessing or enumerating record ids (idurar#1428). - mount adminAuth.isValidAuthToken on the /download route - add request.download() which fetches the PDF via axios with the Authorization header and saves it as a blob, since window.open cannot send auth headers - switch all four download call sites to request.download() Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The /download route was mounted without the isValidAuthToken middleware, allowing anyone to download any invoice, quote or payment PDF by guessing or enumerating record ids (#1428).
Description
The
/downloadroute was mounted without theisValidAuthTokenmiddleware, allowing anyone to download any invoice, quote or payment PDF without logging in, just by guessing or enumerating record ids.Changes:
adminAuth.isValidAuthTokenon the/downloadroute inbackend/src/app.js— the same middleware already protecting the/apiroutes (one line).window.open()cannot send anAuthorizationheader, so the backend fix alone would break the download buttons. Addedrequest.download()infrontend/src/request/request.js, which fetches the PDF via axios with the auth token (responseType: 'blob') and saves it, following the existingincludeToken()/errorHandlerpattern. Switched all four download call sites (ERP panel DataTable and ReadItem, Payment ReadItem, Dashboard RecentTable) to use it.Note: complementary to #1484 / #1476 / #1473, which fix the password-update IDOR from the same issue but do not touch the download route.
Related Issues
Fixes the unauthenticated PDF download part of #1428.
Steps to Test
GET http://localhost:8888/download/invoice/invoice-<id>.pdf→ 401 Unauthorized (before this fix: returned the PDF).
Authorization: Bearer <token>header→ 200, valid PDF with correct
Content-Type: application/pdfand attachment filename.Screenshots (if applicable)
N/A — no visual changes; download buttons behave the same for logged-in users.
Checklist
Two boxes stay unchecked honestly: no documentation exists for this route (nothing to update), and the code needed no comments — it follows existing patterns. Checking boxes that don't apply looks worse than leaving them.