Giter Club home page Giter Club logo

ring-ssl's Introduction

Ring-SSL Build Status

Ring middleware for managing HTTPS requests.

This library includes middleware to parse the X-Forwarded-Proto header, middleware that redirects HTTP requests to HTTPS URLs, and middleware that adds the Strict-Transport-Security header to responses.

Installation

Add the following dependency to your deps.edn file:

ring/ring-ssl {:mvn/version "0.4.0"}

Or to your Leiningen project file:

[ring/ring-ssl "0.4.0"]

Documentation

Thanks

This project was originally conceived and developed by James Conroy-Finn.

License

Copyright © 2024 James Conroy-Finn, James Reeves

Released under the MIT license, same as Ring.

ring-ssl's People

Contributors

jeffh avatar weavejester 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ring-ssl's Issues

expire hsts cache & invert ssl redirect

Say I use wrap-ssl-redirect for the case the user loads a website using http to get him redirected to the https version. I also use wrap-hsts for the second time and so on, so that when the user tries to access the website using http, it is immediately converted to https before sending the request.

Then it happens that my new ssl certificate is unsecure and browsers start complaining. Many former users are still accessing the website via https, which will take them to a security page first. To make matters worse, even if they do use http, the link will immediately be converted to https due to the hsts cache.

To solve these issues, I came up with this:

(defn- build-hsts-expire-header
  [{:keys [include-subdomains?] :or {include-subdomains? true}}]
  (str "max-age=" 0
       (if include-subdomains? "; includeSubDomains")))

(defn wrap-expire-hsts
  {:arglists '([handler] [handler options])}
  [handler & [{:as options}]]
  (fn [request]
    (-> (handler request)
        (resp/header "Strict-Transport-Security" (build-hsts-expire-header options)))))

(defn- http-url [url-string port]
  (let [url (java.net.URL. url-string)]
    (str (java.net.URL. "http" (.getHost url) (or port 80) (.getFile url)))))

(defn- get-request? [{method :request-method}]
  (or (= method :head)
      (= method :get)))

(defn wrap-insecure-redirect
  "Middleware that redirects any HTTPS request to the equivalent HTTP URL.
  Accepts the following options:
  :port - the port to use for redirects, defaults to 80."
  {:arglists '([handler] [handler options])}
  [handler & [{:keys [port]}]]
  (fn [request]
    (if (= (:scheme request) :https)
      (-> (resp/redirect (http-url (req/request-url request) port))
          (resp/status   (if (get-request? request) 301 307)))
      (handler request))))

Is there an easier way to solve this? If not, how about including this use case in ring-ssl along the lines of undoing ssl?

Sample code

Is there a tutorial somewhere. so I can set up a stand alone ring server with self signed TLS cert?

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.