All Projects → arkadiyt → ssrf_filter

arkadiyt / ssrf_filter

Licence: MIT license
A ruby gem for defending against Server Side Request Forgery (SSRF) attacks

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to ssrf filter

Ssrf Testing
SSRF (Server Side Request Forgery) testing resources
Stars: ✭ 1,718 (+2426.47%)
Mutual labels:  ssrf, server-side-request-forgery
runfile
Command line for your projects
Stars: ✭ 22 (-67.65%)
Mutual labels:  gem
grape-jwt-authentication
A reusable Grape JWT authentication concern
Stars: ✭ 31 (-54.41%)
Mutual labels:  gem
lockup
Lockup Gem
Stars: ✭ 111 (+63.24%)
Mutual labels:  gem
RandomProxyRuby
Tiny Library for get random proxy (free).
Stars: ✭ 16 (-76.47%)
Mutual labels:  gem
git-reclone
reclone your git repo
Stars: ✭ 11 (-83.82%)
Mutual labels:  gem
flyyer-ruby
Ruby helpers to create https://cdn.flyyer.io URLs | Og:Image as a Service
Stars: ✭ 13 (-80.88%)
Mutual labels:  gem
click house
Modern Ruby database driver for ClickHouse
Stars: ✭ 133 (+95.59%)
Mutual labels:  gem
fcmpush
Firebase Cloud Messaging API wrapper for Ruby, suppot HTTP v1 API including access_token auto refresh feature.
Stars: ✭ 44 (-35.29%)
Mutual labels:  gem
Vanhiupun.github.io
🏖️ Vanhiupun's Awesome Site ==> another theme for elegant writers with modern flat style and beautiful night/dark mode.
Stars: ✭ 57 (-16.18%)
Mutual labels:  gem
madness
Instant Markdown Server
Stars: ✭ 54 (-20.59%)
Mutual labels:  gem
exprolog
ProxyLogon Full Exploit Chain PoC (CVE-2021–26855, CVE-2021–26857, CVE-2021–26858, CVE-2021–27065)
Stars: ✭ 131 (+92.65%)
Mutual labels:  ssrf
tinify-ruby
Ruby client for the Tinify API.
Stars: ✭ 41 (-39.71%)
Mutual labels:  gem
hscode
📘🖥 A command line reference tool for http status codes.
Stars: ✭ 31 (-54.41%)
Mutual labels:  gem
socket.io-rails
Rails asset pipeline wrapper for socket.io
Stars: ✭ 57 (-16.18%)
Mutual labels:  gem
acts as user
A gem which handles multiple types of users on a rails app
Stars: ✭ 24 (-64.71%)
Mutual labels:  gem
acts as inheritable
Inheritable functionality for ActiveRecord models.
Stars: ✭ 24 (-64.71%)
Mutual labels:  gem
proxylogscan
A fast tool to mass scan for a vulnerability on Microsoft Exchange Server that allows an attacker bypassing the authentication and impersonating as the admin (CVE-2021-26855).
Stars: ✭ 145 (+113.24%)
Mutual labels:  ssrf
reproducible-continual-learning
Continual learning baselines and strategies from popular papers, using Avalanche. We include EWC, SI, GEM, AGEM, LwF, iCarl, GDumb, and other strategies.
Stars: ✭ 118 (+73.53%)
Mutual labels:  gem
warm-blanket
Ruby gem for warming up web services on boot
Stars: ✭ 1 (-98.53%)
Mutual labels:  gem

ssrf_filter Gem Tests Coverage Status Downloads License

Table of Contents

What's it for

ssrf_filter makes it easy to defend against server side request forgery (SSRF) attacks. SSRF vulnerabilities happen when you accept URLs as user input and fetch them on your server (for instance, when a user enters a link into a Twitter/Facebook status update and a content preview is generated).

Users can pass in URLs or IPs such that your server will make requests to the internal network. For example if you're hosted on AWS they can request the instance metadata endpoint http://169.254.169.254/latest/meta-data/ and get your IAM credentials.

Attempts to guard against this are often implemented incorrectly, by blocking all ip addresses, not handling IPv6 or http redirects correctly, or having TOCTTOU bugs and other issues.

This gem provides a safe and easy way to fetch content from user-submitted urls. It:

  • handles URIs/IPv4/IPv6, redirects, DNS, etc, correctly
  • has 0 runtime dependencies
  • has a comprehensive test suite (100% code coverage)
  • is tested against ruby 2.6, 2.7, 3.0, 3.1, and ruby-head

Quick start

  1. Add the gem to your Gemfile:
gem 'ssrf_filter', '~> 1.1.1'
  1. In your code:
require 'ssrf_filter'
response = SsrfFilter.get(params[:url]) # throws an exception for unsafe fetches
response.code
=> "200"
response.body
=> "<!doctype html>\n<html>\n<head>\n..."

API reference

SsrfFilter.get/.put/.post/.delete/.head/.patch(url, options = {}, &block)

Fetches the requested url using a get/put/post/delete/head/patch request, respectively.

Params:

  • url — the url to fetch.
  • options — options hash (described below).
  • block — a block that will receive the HTTPRequest object before it's sent, if you need to do any pre-processing on it (see examples below).

Options hash:

  • :scheme_whitelist — an array of schemes to allow. Defaults to %w[http https].
  • :resolver — a proc that receives a hostname string and returns an array of IPAddr objects. Defaults to resolving with Ruby's Resolv. See examples below for a custom resolver.
  • :max_redirects — Maximum number of redirects to follow. Defaults to 10.
  • :params — Hash of params to send with the request.
  • :headers — Hash of headers to send with the request.
  • :body — Body to send with the request.
  • :http_options – Options to pass to Net::HTTP.start. Use this to set custom timeouts or SSL options.
  • :request_proc - a proc that receives the request object, for custom modifications before sending the request.

Returns:

An HTTPResponse object if the url was fetched safely, or throws an exception if it was unsafe. All exceptions inherit from SsrfFilter::Error.

Examples:

# GET www.example.com
SsrfFilter.get('https://www.example.com')

# Pass params - these are equivalent
SsrfFilter.get('https://www.example.com?param=value')
SsrfFilter.get('https://www.example.com', params: {'param' => 'value'})

# POST, send custom header, and don't follow redirects
begin
  SsrfFilter.post('https://www.example.com', max_redirects: 0,
    headers: {'content-type' => 'application/json'})
rescue SsrfFilter::Error => e
  # Got an unsafe url
end

# Custom DNS resolution and request processing
resolver = proc do |hostname|
  [IPAddr.new('2001:500:8f::53')] # Static resolver
end
# Do some extra processing on the request
request_proc = proc do |request|
  request['content-type'] = 'application/json'
  request.basic_auth('username', 'password')
end
SsrfFilter.get('https://www.example.com', resolver: resolver, request_proc: request_proc)

# Stream response
SsrfFilter.get('https://www.example.com') do |response|
  response.read_body do |chunk|
    puts chunk
  end
end

Changelog

Please see CHANGELOG.md. This project follows semantic versioning.

Contributing

Please see CONTRIBUTING.md.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].