ssrf
A request sent to a URL a request chose.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule ssrf - Level
- warning
- Reads
- Every file
- Fix
- None: the safe form depends on what the value is meant to be
Why
The server sends a request to a URL, or a host, taken from a request, so whoever sends it can make the server reach addresses only it can, such as a cloud's metadata service, an admin port on localhost, or a service on the internal network, and read what they answer. Check the address the host resolves to against a list of allowed or blocked ranges before connecting, connect to that address rather than resolving the name again, and check every redirect the same way.
The fix, as Ur suggests it: check the resolved address, pin it, and check each redirect.
For agents
Never send a request to a URL taken from a request without checking the address it resolves to, connecting to that address, and checking each redirect.
Example
app/controllers/previews_controller.rbclass PreviewsController < ApplicationController
def show
render plain: Net::HTTP.get(URI(params[:url]))
end
end
$ ur scan --rule ssrf
warning[ssrf]: `params`, a request parameter, reaches `Net::HTTP.get`
--> ./app/controllers/previews_controller.rb:3:19 method `show`
= step 1: ./app/controllers/previews_controller.rb:3:37 `params`, a request parameter,
= step 2: ./app/controllers/previews_controller.rb:3:33 passed to `URI`
= hint: check the resolved address, pin it, and check each redirect
= see: Server Side Request Forgery Prevention Cheat Sheet, OWASP (2025-01-01), https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html
scanned 1 file (no framework recognized)
ssrf: 1 high, 0 medium
1 finding and 0 of medium confidence
Source
Server Side Request Forgery Prevention Cheat Sheet, OWASP (2025-01-01).