Popularity
6.4
Declining
Activity
0.0
Stable
8
6
4

Monthly Downloads: 25
Programming language: Haskell
License: MIT License
Tags: Web     Yesod    

yesod-csp alternatives and similar packages

Based on the "yesod" category.
Alternatively, view yesod-csp alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of yesod-csp or a related project?

Add another 'yesod' Package

README

yesod-csp

The aim of this library is to make it easy to add correct Content Security Policy headers to your responses. This reduces the risk of loading bad assets or scripts.

Using the data types

The following code:

getHomeR :: Handler Html
getHomeR = do
  cspPolicy [ScriptSrc (Self :| []), StyleSrc (Https :| [Self])]
  defaultLayout [whamlet|hello|]

will ensure that a Content-Security-Policy: script-src 'self'; style-src https: 'self' header is set. In this example we only want to load scripts from our own domain, and we only want styles that come from our domain or over https.

This is a work in progress, not battle-hardened! Use with caution and confirm you're getting the results you need.

Examples

This module contains a host of runnable example Yesod handlers which set various CSP headers.

Template Haskell support

I'm working on Template Haskell support so you don't need to write the ADTs yourself explicitly. You can get the same compile-time checking with the familar CSP DSL:

getHomeR :: Handler Html
getHomeR = do
  cspPolicy [csp|img-src 'self' https:; script-src https://foo.com|]
  ...

You can add in your dynamic urls in scope:

getHomeR :: Handler Html
getHomeR = do
  let url = fromJust (escapeAndParseURI ...)
  cspPolicy [csp|img-src 'self' $url|]
  ...