Giter Site home page Giter Site logo

reverse-proxy's Introduction

Reverse proxy

This project represents a simple demo of a reverse proxy. A reverse proxy is a server that accepts a request from a client, forwards the request to another one of many other servers, and returns the results from the server that actually processed the request to the client as if the proxy server had processed the request itself.

Some of the features this project have are:

- Inspecting and masking sensitive json data
- Logging all input and output traffic
- Block requests based on set of predefined rules

Proxy also adds header to your forwarded responses. X-Proxy-Error which can be true or false. It signals internal proxy errors proxy-ing or inspecting the request.

Running Project

This project features a json endpoint that allows easy testing of reverse proxy.

To run both proxy and the json endpoint all you need to do is docker compose up

  1. It will create a container of proxy listening on port 8000
  2. It will create a container of jsonendpoint listening on port 8001
  3. Proxy will load config.json file containing request blocking rules as well as config to which host and scheme to forward requests
  4. To test the proxy masking you can send a GET request to proxy
curl localhost:8000
  1. To test blocking you can send a DELETE request to proxy
curl -X POST localhost:8000
  1. To test forwarding request without masking send a PUT request
curl -X PUT localhost:8000

Running tests

Whole project is comprehensively using interfaces in order to allow easy unit testing. Due to that whole project is also unit tested. For some tests snapshoting library cupaloy was used. It generates snapshots in ./snapshots dir.

To run tests

go test ./...

Forwarding requests

Proxy will forward requests to a host specified in config.json in field forward_host It will use a scheme specified as forward_scheme

Masking Rules

Default masking rules for PII (Personally identifiable information) are quite simple and if it were a real world project i would aim to use a more comprehensive set of detections instead of a couple of simple detections. They are located here and are easily extendible

Blocking rules explained

As explained in top comment: If this was a real world user facing software i would use open policy agent rego, however my understanding of the task was that it was required to build some kind of rules mechanism myself.

Blocking rules are loaded from config.json block field Blocking rules are designed in a way that you can compose different rules in order to build different combinations of blocking rules.

For example if you want to block all delete or posts requests you use this blocking rules:


{
    "forward_host": "jsonendpoint:8000",
    "forward_scheme": "http",
    "block": [
        [
            {
                "method": "POST"
            }
        ],
        [
            {
                "method": "DELETE"
            }
        ]
    ]
}

If on the other hand you would like to block all POST requests that start with path /api or any DELETE request


{
    "forward_host": "jsonendpoint:8000",
    "forward_scheme": "http",
    "block": [
        [
            {
                "method": "POST"
            },
            {
                "path": "/api"
            }
        ],
        [
            {
                "method": "DELETE"
            }
        ]
    ]
}

First level of block property acts as OR (||) and second level acts as AND (&&) when matching

Possible blocks

All guards used for blocks are located here

  1. Method block

{
    "method": "DELETE"
}

  1. Path block

{
    "path": "/api"
}

  1. Query Parameter block

{
    "query_param": "userID"
    "value": "userID"
}

  1. Header block

{
    "header": "Content-Type"
    "value": "text/html; charset=utf-8"
}

reverse-proxy's People

Contributors

vjerci avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.