blob: f7bc478d97a7de913499cccd5645a33c506a8d84 [file] [log] [blame]
#pragma once
#include <crow/http_request.h>
#include <crow/http_response.h>
namespace crow {
static const char* strictTransportSecurityKey = "Strict-Transport-Security";
static const char* strictTransportSecurityValue =
"max-age=31536000; includeSubdomains; preload";
static const char* uaCompatabilityKey = "X-UA-Compatible";
static const char* uaCompatabilityValue = "IE=11";
static const char* xframeKey = "X-Frame-Options";
static const char* xframeValue = "DENY";
static const char* xssKey = "X-XSS-Protection";
static const char* xssValue = "1; mode=block";
static const char* contentSecurityKey = "X-Content-Security-Policy";
static const char* contentSecurityValue = "default-src 'self'";
static const char* pragmaKey = "Pragma";
static const char* pragmaValue = "no-cache";
static const char* cacheControlKey = "Cache-Control";
static const char* cacheControlValue = "no-Store,no-Cache";
struct SecurityHeadersMiddleware {
struct Context {};
void beforeHandle(crow::Request& req, Response& res, Context& ctx) {}
void afterHandle(Request& req, Response& res, Context& ctx) {
/*
TODO(ed) these should really check content types. for example,
X-UA-Compatible header doesn't make sense when retrieving a JSON or
javascript file. It doesn't hurt anything, it's just ugly.
*/
res.addHeader(strictTransportSecurityKey, strictTransportSecurityValue);
res.addHeader(uaCompatabilityKey, uaCompatabilityValue);
res.addHeader(xframeKey, xframeValue);
res.addHeader(xssKey, xssValue);
res.addHeader(contentSecurityKey, contentSecurityValue);
res.addHeader(pragmaKey, pragmaValue);
res.addHeader(cacheControlKey, cacheControlValue);
}
};
} // namespace crow