Coder Social home page Coder Social logo

http-grpc-filter's Introduction

http-grpc-filter

Build Status codecov

Overview

The API analyzes an HTTP user agent and decides to block or allow it. If the user agent header is from a Safari browser, it should return a decision to block the request. If it is from a Firefox browser, it should allow the request.

A gRPC client and server implements a single endpoint that receives the user agent string, analyzes it, and returns the result.

The terminal CLI uses the client to call the API.

Getting Started

Prerequisites

Install Protoc

The Protoc compiler is needed to generate the gRPC code.

If you are using MacOS, you can use Homebrew:

$ brew install protobuf

Verify Installation of Protoc

The protoc compiler should be included in your PATH. Verify by running the following command:

$ protoc --version
libprotoc 24.3 # this is an example version

Running

Open two terminals or tabs in a terminal.

Start the server in one terminal (or separate tab):

$ cargo run --bin echo-server

Start the client in another terminal (or separate tab):

The last part of the input string should be a HTTP User Agent. Mozilla has provided examples of user agent strings for different browsers.

$ cargo run --bin echo-client -- "Hello World\!"

Example 1: Firefox User Agent

Run client after starting the server:

$ cargo run --bin echo-client -- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0"

RESPONSE=EchoResponse { message: "Accepting the Request.", user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0" }"

Example 2: Safari User Agent

Run client after starting the server:

$ cargo run --bin echo-client -- "Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1"

RESPONSE=EchoResponse { message: "Blocking the Request.", user_agent: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1\n" }

Testing

$ cargo test

#################################### Sample output below ####################################
Finished test [unoptimized + debuginfo] target(s) in 0.04s
     Running unittests src/main.rs (target/debug/deps/echo_client-3d3566e115c08a41)

running 1 test
test tests::test_bad_client_connection ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests src/server.rs (target/debug/deps/echo_server-ffaaf4bd0ea8fe8a)

running 1 test
test tests::test_bad_address ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Troubleshooting

  • If you see a dquote> on the terminal when running the client, history expansion might be enabled in your terminal, so retry the input string and escape backspaces.
  • Use CTRL+G to escape dquote>

Example

$ cargo run --bin echo-client --"Hello World!"

dquote>

Click CTRL+G then retype the following:

$ cargo run --bin echo-client --"Hello World\!"

Future Work

  • See the issues for future feature and enchancement ideas.

http-grpc-filter's People

Contributors

iotaaxel avatar

Watchers

 avatar  avatar

http-grpc-filter's Issues

Add Github Actions workflow

Set up the workflow and add the following:

  • testing section
  • code coverage section
  • linter section

Additionally, add icons with the testing status and code coverage percentage to the README

For the linter, do the following (if possible or reasonable):

  • Make the CI/CD pipeline run the linter against every PR and fail the build if any errors exist.
  • Use a code formatter like Prettier and enforce a post-commit hook than formats every commit.

Add Regex backwards compatibility for Firefox UAs

Problem:
Some Firefox user agents are not compatible with the Regex.

Examples:

  • User agents ending not in the form Firefox/XXX.X or Firefox/XX.X will currently be blocked.
  • Some blocked user agents include the pre-release versions, + versions, beta versions, alpha versions, plugin version, Debian versions, versions with tagging, and versions of form Firefox/X.X or Firefox/X.X.X or Firefox/X.X.X.X

References:
useragentstring.com

Considerations:
Mozilla probably has an API with all the Firefox User Agent strings but initially minimal dependency on third-party software was a goal since the authors may or may not actively maintain the code in the future.

Add API Documentation

Update the README to have the following sections:

  1. Overview
  2. Setup / Getting Started
    • Includes prerequisites
  3. Running
  4. Testing
  5. Troubleshooting
  6. Future Work / Insights

Add deployment instructions

Objective:

  • Docker to deploy application

Resources:

  • See Docker's language-specific deployment guides as reference

Considerations:

  • Check the pricing for deploying a container to AWS EC2, Azure ACI, or another cloud service.
    • The Docker image can be run inside a container.
    • ECS stands for Amazon EC2 Container Service.
    • ACI stands for Azure Container Instances.
    • Consider using fly.io as a cheap alternative but note that there is no free tier.

Updates

  • Update the CI/CD yaml workflow file
  • Add instructions to README

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.