Class: Scryer::Rules::SsrfRule
- Inherits:
-
Scryer::Rule
- Object
- Scryer::Rule
- Scryer::Rules::SsrfRule
- Defined in:
- lib/scryer/rules/ssrf_rule.rb
Overview
Flags an outbound HTTP call (Net::HTTP, URI.open/bare open
via open-uri, HTTParty, Faraday, RestClient) where an argument
references params directly — the request's destination is
user-controlled, which lets an attacker make the server issue requests
to internal services, cloud metadata endpoints, or anywhere else on
its network (server-side request forgery).
Constant Summary collapse
- DANGEROUS_CALLS =
{ "Net::HTTP" => %w[get get_response post post_form], "URI" => %w[open], "HTTParty" => %w[get post put delete], "Faraday" => %w[get post put delete], "RestClient" => %w[get post put delete] }.freeze
Instance Attribute Summary
Attributes inherited from Scryer::Rule
Instance Method Summary collapse
Methods inherited from Scryer::Rule
Constructor Details
This class inherits a constructor from Scryer::Rule
Instance Method Details
#scan ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/scryer/rules/ssrf_rule.rb', line 23 def scan findings = [] Ast.each_node(sexp) do |node| next unless Ast.tagged?(node, :method_add_arg, :command, :command_call) inner = Ast.tagged?(node, :method_add_arg) ? node[1] : node receiver_and_name = Ast.call_name(inner) next unless receiver_and_name receiver, method_name = receiver_and_name next unless dangerous_call?(receiver, method_name) args = Ast.call_arguments(node) next unless args.any? { |a| Ast.references_params?(a) } line = Ast.line_of(node) findings << finding( line: line, message: "`#{describe_call(receiver, method_name)}` is called with a URL/argument " \ "that references `params` — the server can be made to issue a request to " \ "any host an attacker chooses, including internal services and cloud " \ "metadata endpoints (e.g. `169.254.169.254`) that aren't meant to be " \ "reachable from outside.", suggested_fix: "Validate the destination against an allowlist of known-safe hosts " \ "before making the request, rather than passing the user-supplied " \ "value straight through — and reject internal/link-local IP ranges " \ "explicitly if the allowlist is host-based (DNS can still resolve to one)." ) end findings end |