Details
Then validate the Location header with isSSRFSafeURL() before following it manually. This approach prevents the get_headers() call itself from performing SSRF via the redirect.
Note: Option 1 is simpler but still allows get_headers() to make an initial request to the redirect target (header-only SSRF). Option 2 eliminates both SSRF vectors. Both options should be combined for defense-in-depth.
Credit
This vulnerability was discovered and reported by bugbunny.ai.