yesod-csp-0.2.0.0: Add CSP headers to Yesod apps

Safe HaskellNone
LanguageHaskell2010

Yesod.Csp

Description

Add CSP headers to Yesod apps. This helps reduce the risk of exposure to XSS and bad assets.

Synopsis

Documentation

cspPolicy :: MonadHandler m => DirectiveList -> m () Source

Adds a Content-Security-Policy header to your response.

getExample1R :: Handler Html
getExample1R = do
  -- only allow scripts from my website
  cspPolicy [ScriptSrc (Self :| [])]
  defaultLayout $ do
    addScriptRemote "http://httpbin.org/i_am_external"
    [whamlet|hello|]

getCspPolicy :: DirectiveList -> Text Source

Returns a generated Content-Security-Policy header.

escapeAndParseURI :: Text -> Maybe EscapedURI Source

Escapes ';' '\'' and ' ', and parses to URI

type DirectiveList = [Directive] Source

A list of restrictions to apply.

data Directive Source

A restriction on how assets can be loaded. For example ImgSrc concerns where images may be loaded from.

type SourceList = NonEmpty Source Source

A list of allowed sources for a directive.

data Source Source

Represents a location from which assets may be loaded.