GithubHelp home page GithubHelp logo

warp's Introduction

warp

Signed URL redirection service.

Why?

Firebase Dynamic Links is a useful service that allows me to generate sharable social links. The generated links can be shared to social networks with specified title, description and image.

function getDynamicLink(pageUrl, imageUrl, title, description) {
  const dynamicLink = 'https://dtinth.page.link/?' + [
    `link=${encodeURIComponent(pageUrl)}`,
    `st=${encodeURIComponent(title)}`,
    `sd=${encodeURIComponent(description)}`,
    `si=${encodeURIComponent(imageUrl)}`,
  ].join('&')
  return dynamicLink
}

However, for security, it is a best practice to restrict the usage of Dynamic Page Link to only domains that I own. This poses a problem when I want to link to 3rd party domains; I would have to edit the allowlist pattern for each new domain that I link to.

Instead of doing that I decided to create a signed URL redirection service. A redirect is authorized if it is properly cryptographically signed.

Generating signed URLs

  1. Get the URL to sign.

    https://github.com/dtinth
    
  2. Use TweetNaCl to sign the URL with my own private key. This generates a signature. Encode the signature as base64url.

    k-4eL27uaLEgfSvL_KW9NeE2LxW_4gocHxerjOSBno7aR7MHUgGhj5CmHLW2LBgt6rxR_0zrZskZm66RwDtUCA
    
  3. Construct a signed URL which lives on my personal domain spacet.me.

    https://warp.spacet.me/api/go
        ?u=https://github.com/dtinth
        &i=automatron
        &s=k-4eL27uaLEgfSvL_KW9NeE2LxW_4gocHxerjOSBno7aR7MHUgGhj5CmHLW2LBgt6rxR_0zrZskZm66RwDtUCA
    
  4. Use that signed URL to generare a Firebase Dynamic Link.

Parameters

Query Parameter Description
u URL to redirect to
i Issuer of the signed URL, which is registered in the API's source code
s The signature, base64url-encoded
p Prefix length for delegation (see below)

Delegation

In the above example, every individual URLs must be personally signed by me. But sometimes I want to allow others to use this service, but with restrictions. A common restriction is by using URL prefixes. Instead of signing the whole URL, a URL prefix can be signed instead.

  1. Get the URL prefix to sign, and append * to it to get a URL pattern.

    https://wonderful.software/*
    

    Also count the prefix length (excluding the *), here it is 27 characters.

  2. Sign the pattern to generate a signature:

    QKrnwHJLl7kHMPllMozh38viYGLYvOWH9CRwrtUhMlnEa6Ill3nBEtvasGf1ygFp-tINQj_uyzCni1EsbqWYBw
    
  3. Construct a signed URL:

    https://warp.spacet.me/api/go
        ?u=https://wonderful.software/elect-live/pdd/
        &p=27
        &i=automatron
        &s=QKrnwHJLl7kHMPllMozh38viYGLYvOWH9CRwrtUhMlnEa6Ill3nBEtvasGf1ygFp-tINQj_uyzCni1EsbqWYBw
    
  4. Use the signed URL.

How I am using this

I sign URLs through my personal chat bot automatron. It takes care of constructing the signed URL and holds the private key encrypted.

Screenshot

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.