Giter Club home page Giter Club logo

nginx-jwt's Introduction

Proof of concept of NGINX + JWT Validation

This is a proof of concept of JWT token validation with NGINX using NJS, a subset of Javascript that allows extending NGINX functionalities: https://nginx.org/en/docs/njs/
We will try to consume a protected static file, that will be accessible only when a valid token is provided.

Please note:
NGINX can already validate JWT Tokens, but only with the Plus subscription

https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-jwt-authentication/

https://www.nginx.com/products/buy-nginx-plus/

Prerequisites

  • Docker
  • Bash
  • Web Browser

Project startup

Clone the repository, cd into and then

bash pull.sh
bash start.sh

The container will start and attach to port 81.

You must have a valid JWT token, for example the following one

http://localhost:81/private/private_file.txt?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.XbPfbIHMI6arZ3Y922BhjWgQzWXcXNrz0ogtVhfEd2o

will return private file

but using a wrong token

http://localhost:81/private/private_file.txt?token=xxx

will return an error.

Moreover, a static test file with no JWT validation is provided at

http://localhost:81/static/static_file.txt

The secret used to validate this token is "secret" (look in config\module.js)

Stop

bash stop.sh

Benchmark

A benchmark to measure the overhead of this kind of validation is provided here: https://github.com/lombax85/nginx-njs-benchmark

Credits

nginx-jwt's People

Contributors

lombax85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nginx-jwt's Issues

base64 encoder/decoder

First of all: great PoC. I am trying to use it in my websites, but am struggling with base64. Actually I was trying to share a 16 bytes secret base64 encoded, and failed. I tracked it down to:

var t = Base64.decode("1C2qoD9rikCwLc6ij4diCw==");
var s = Base64.encode(t);
// s contains 1K3qoL9r6oCwLc6i74eiCw==

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.