The vulnerability is a Server-Side Request Forgery (SSRF) in the external file upload functionality of Payload CMS. The root cause was the automatic following of HTTP redirects when fetching a file from a user-provided URL. An attacker could supply a URL that passed the initial security checks but then redirected to a URL on the internal network, bypassing the validation.
The analysis of the patch commit 1041bb6 reveals changes in two key files: packages/payload/src/uploads/getExternalFile.ts and packages/payload/src/uploads/safeFetch.ts.
-
safeFetch in packages/payload/src/uploads/safeFetch.ts: The patch adds redirect: 'manual' to the options passed to undiciFetch. Before this change, safeFetch would automatically follow redirects, making it a component in the SSRF vulnerability chain.
-
getExternalFile in packages/payload/src/uploads/getExternalFile.ts: This function orchestrates the file download. The patch replaces the direct call to fetch or safeFetch with a while loop that manually handles redirects. It inspects the Location header of 3xx responses, re-runs security checks on the new URL, and limits the total number of redirects to prevent loops. The original implementation lacked this manual redirect handling, making it the primary vulnerable function.
Therefore, both getExternalFile and the original version of safeFetch are identified as the vulnerable functions that would appear in a runtime profile during exploitation.