[Security] Unauthenticated SSRF & local file read via generateInvoicePDF Server Action
Description
The Server Action generateInvoicePDF (exported from app/(app)/apps/invoices/actions.ts) does not perform any authentication or session validation. An unauthenticated attacker can call it directly via the Next-Action header. The businessLogo field is passed unsanitised to the @react-pdf/renderer image resolver, which on the server:
- Treats absolute paths (e.g.,
/etc/passwd) as local files and callsfs.readFile(). - Treats
http:///https://URLs as remote resources and makes server‑sidefetch()requests.
This enables two attack vectors:
Local file read – any file on the server filesystem can be opened (with the privileges of the Node.js process, which is
rootin the official Docker image).
Note: Only image files (PNG/JPEG) or SVG/XML that render as text are reflected in the returned PDF; other formats are read but discarded, so they are not exfiltrated via the response.SSRF – the server can probe internal services; if those services respond with an image or SVG, the content is embedded in the generated PDF and can be retrieved.
This issue is especially critical in SaaS/multi‑tenant deployments, where an attacker could read other users’ uploaded invoice images (if their file UUID is known) or access internal network resources that return images/SVGs.
Steps to Reproduce
Obtain the Server Action identifier
Send an unauthenticated GET request to/apps/invoices. The page is accessible without a session (the middleware does not protect/apps/*).
Extract the action ID from the_next/static/chunks/*.jsfiles – it is the argument passed tocreateServerReference(...).Craft a POST request to the same endpoint with the
Next-Actionheader set to that ID, and a JSON body that includes abusinessLogovalue pointing to a local file or an internal URL.Example (simplified):
{ "title": "test", "businessLogo": "/etc/hosts", // or "http://127.0.0.1:8080/admin" // ... other required fields (any valid invoice data) }Send the request without any authentication cookie – the server will process it and return a PDF.
- If
businessLogopoints to a local image or an SVG, that content will appear in the PDF. - If it points to a non‑image file, the read still occurs (server logs may show the attempt), but the PDF will not leak the content.
- If
(For a concrete demonstration, I can provide a full payload privately upon request.)
Expected Behavior
The Server Action should reject unauthenticated requests and sanitise/restrict the businessLogo field to trusted URLs (e.g., only data URIs or allowed domains), never accepting filesystem paths or arbitrary http:// destinations.
Actual Behavior
No authentication check is performed, and businessLogo is passed directly to the image resolver, which resolves both absolute filesystem paths and arbitrary URLs.
Environment
- Affected versions: 0.8.5 and earlier (including the latest
ghcr.io/vas3k/taxhacker:latestimage). - Official Docker image runs as
root, increasing the risk.
Additional Context
- The middleware (
proxy.ts) does not cover/apps/*routes or Server Action POST endpoints, which makes this action reachable without a session. - The action ID is deterministic and can be easily extracted from the client‑side chunks, making exploitation trivial.
- I believe this should be treated as a security‑critical issue. I’m happy to provide more details or help test a fix, but I’d suggest keeping further discussion private until a patch is available (e.g., using GitHub Security Advisories).
Proposed Fix
- Add
getSession()/getCurrentUser()validation at the beginning ofgenerateInvoicePDF. - Restrict
businessLogotodata:image/URIs or a whitelist of external domains; rejectfile://, absolute paths, and rawhttp:///https://URLs. - Consider moving the action behind the authentication middleware or adding per‑route auth checks.
Source: vas3k/TaxHacker