Adds security headers in response
This commit is contained in:
parent
91a5514aee
commit
f816f6d591
@ -14,6 +14,7 @@ _hastatic_ is a very small web server for serving static files from a Docker con
|
|||||||
- Supports custom index files for URLs ending with "/".
|
- Supports custom index files for URLs ending with "/".
|
||||||
- Takes care to not serve hidden files.
|
- Takes care to not serve hidden files.
|
||||||
- Adds caching headers automatically.
|
- Adds caching headers automatically.
|
||||||
|
- Adds security headers automatically.
|
||||||
- Caches file descriptors and info for better performance.
|
- Caches file descriptors and info for better performance.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -24,6 +24,14 @@ import Paths_hastatic (version)
|
|||||||
|
|
||||||
data TLS = Okay TLS.TLSSettings | Error String | None
|
data TLS = Okay TLS.TLSSettings | Error String | None
|
||||||
|
|
||||||
|
addSecureHeaders :: Middleware
|
||||||
|
addSecureHeaders = modifyResponse $ mapResponseHeaders (++ secureHeaders)
|
||||||
|
where
|
||||||
|
secureHeaders = [ ("Referrer-Policy", "strict-origin-when-cross-origin")
|
||||||
|
, ("X-Frame-Options", "SAMEORIGIN")
|
||||||
|
, ("X-XSS-Protection", "1; mode=block")
|
||||||
|
]
|
||||||
|
|
||||||
indexHTML :: T.Text -> Middleware
|
indexHTML :: T.Text -> Middleware
|
||||||
indexHTML indexFile app req respond =
|
indexHTML indexFile app req respond =
|
||||||
let path = pathInfo req
|
let path = pathInfo req
|
||||||
@ -55,6 +63,7 @@ application excludedPaths = do
|
|||||||
indexFile <- T.pack . fromMaybe "index.html" <$> lookupEnv "IDX_FILE"
|
indexFile <- T.pack . fromMaybe "index.html" <$> lookupEnv "IDX_FILE"
|
||||||
cache <- initCaching PublicStaticCaching
|
cache <- initCaching PublicStaticCaching
|
||||||
return
|
return
|
||||||
|
. addSecureHeaders
|
||||||
. indexHTML indexFile
|
. indexHTML indexFile
|
||||||
. staticPolicy' cache polcy
|
. staticPolicy' cache polcy
|
||||||
. notFoundHandler
|
. notFoundHandler
|
||||||
|
Loading…
Reference in New Issue
Block a user