This package contains a collections of plugins for fiery that handles server-side security in different ways. Currently it contains:
SecurityHeaders
Inspired by helmet.js, this plugin will configure and set a range of security related headers on all outgoing responses.
CORS
This plugin will help you set up Cross-Origin-Resource-Sharing (CORS) for one or more paths in your server.
ResourceIsolation
This plugin lets you configure Resource Isolation Policies for one or more paths in your server.
# You can install marquee from CRAN
::pak("firesafety")
pak
# Or get the development version from Github
::pak("thomasp85/firesafety") pak
Using the plugins is straightforward as they all come with sensible defaults that serve as a good starting point. Remember the best security is as strict as your functionality allows. If you find that your server logic no longer works after adding these any of these plugins, investigate why, and relax the settings for the specific area that is causing issues.
<- fiery::Fire$new()
app
# Set security headers but remove those related to UI (we assume this is a REST
# server) and rely on defaults for the rest
<- firesafety::SecurityHeaders$new(
headers content_security_policy = NULL,
cross_origin_embedder_policy = NULL,
cross_origin_opener_policy = NULL,
origin_agent_cluster = NULL,
referrer_policy = NULL,
x_dns_prefetch_control = NULL,
x_download_options = NULL,
x_frame_options = NULL,
x_xss_protection = NULL
)
# decrease the max age of STS after creation
$strict_transport_security <- firesafety::sts(
headersmax_age = 31536000 # 1 year
)
# Add to server
$attach(headers)
app
# Set up CORS for a subset of paths
<- firesafety::CORS$new(
cors path = "global/*",
origin = "https://my-other-website.com"
)
# Add to server
$attach(cors)
app
# Set up RIP for a path and its subpaths
<- firesafety::ResourceIsolation$new(
rip path = "assets/*",
allowed_site = "same-origin"
)
# Add to server
$attach(rip)
app
app#> 🔥 A fiery webserver
#> 🔥 💥 💥 💥
#> 🔥 Running on: 127.0.0.1:8080
#> 🔥 Plugins attached: header_routr
#> 🔥 security_headers
#> 🔥 request_routr
#> 🔥 cors
#> 🔥 resource_isolation
#> 🔥 Event handlers added
#> 🔥 header: 1
#> 🔥 request: 1