Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/c-rack/plug_cloudflare
Parses CloudFlare's CF-Connecting-IP header into Plug.Conn's remote_ip field.
https://github.com/c-rack/plug_cloudflare
Last synced: 2 months ago
JSON representation
Parses CloudFlare's CF-Connecting-IP header into Plug.Conn's remote_ip field.
- Host: GitHub
- URL: https://github.com/c-rack/plug_cloudflare
- Owner: c-rack
- License: apache-2.0
- Created: 2015-04-25T19:49:41.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-03-12T10:38:18.000Z (almost 3 years ago)
- Last Synced: 2024-11-01T07:33:26.670Z (3 months ago)
- Language: Elixir
- Homepage:
- Size: 50.8 KB
- Stars: 23
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Inspired by mod_cloudflare, this Elixir plug parses Cloudflares CF-Connecting-IP HTTP request header into Plug.Conn's remote_ip field. (Framework Components)
- fucking-awesome-elixir - plug_cloudflare - Inspired by mod_cloudflare, this Elixir plug parses Cloudflares CF-Connecting-IP HTTP request header into Plug.Conn's remote_ip field. (Framework Components)
- awesome-elixir - plug_cloudflare - Inspired by mod_cloudflare, this Elixir plug parses Cloudflares CF-Connecting-IP HTTP request header into Plug.Conn's remote_ip field. (Framework Components)
README
# plug_cloudflare
[![Build Status](https://travis-ci.org/c-rack/plug_cloudflare.png?branch=master)](https://travis-ci.org/c-rack/plug_cloudflare)
[![Module Version](https://img.shields.io/hexpm/v/plug_cloudflare.svg)](https://hex.pm/packages/plug_cloudflare)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/plug_cloudflare/)
[![Total Download](https://img.shields.io/hexpm/dt/plug_cloudflare.svg)](https://hex.pm/packages/plug_cloudflare)
[![License](https://img.shields.io/hexpm/l/plug_cloudflare.svg)](https://github.com/c-rack/plug_cloudflare/blob/master/LICENSE)
[![Last Updated](https://img.shields.io/github/last-commit/c-rack/plug_cloudflare.svg)](https://github.com/c-rack/plug_cloudflare/commits/master)Inspired by [mod_cloudflare](https://github.com/cloudflare/mod_cloudflare), this [Elixir](http://elixir-lang.org/) [plug](https://github.com/elixir-lang/plug) parses [CloudFlare](https://www.cloudflare.com/)'s `CF-Connecting-IP` HTTP request header into [Plug.Conn](http://hexdocs.pm/plug/Plug.Conn.html)'s `remote_ip` field.
## Setup
To use `:plug_cloudflare` in your projects, edit your `mix.exs` file and add `:plug_cloudflare` as a dependency:
```elixir
defp deps do
[
{:plug_cloudflare, ">= 1.2.0"}
]
end
```## Usage
This plug should be one of the first ones in your pipeline.
It is therefore recommended to put it in the endpoint instead of a pipeline.```elixir
defmodule MyApp.Endpoint do
use Phoenix.Endpoint, otp_app: my_appplug Plug.CloudFlare
# Other plugs omitted for clarity
end
```## Behavior
This plug makes an effort to avoid tampering with the remote IP if the app is not running behind Cloudflare. The remote IP will only be changed by this plug if:
1. The CF-Connecting-IP header is present
1. The CF-Connecting-IP header parses to a valid IP address
1. The peer making the request is a Cloudflare IP address## Contribution Process
This project uses the [C4.1 process](http://rfc.zeromq.org/spec:22) for all code changes.
> "Everyone, without distinction or discrimination, SHALL have an equal right to become a Contributor under the
terms of this contract."## Copyright and License
Copyright (c) 2015 Constantin Rack
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.