diff --git a/Cargo.lock b/Cargo.lock index 5c0d9df..3c590b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -258,7 +258,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "channelserver" -version = "0.7.1" +version = "0.8.0" dependencies = [ "actix 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", "actix-web 0.7.13 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/channelserver/Cargo.toml b/channelserver/Cargo.toml index be9849e..a6f0e45 100644 --- a/channelserver/Cargo.toml +++ b/channelserver/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "channelserver" -version = "0.7.1" +version = "0.8.0" authors = ["jr conlin) -> Result &meta_info.remote); - return Ok(HttpResponse::new(http::StatusCode::NOT_FOUND)); + let mut resp = + HttpResponse::new(http::StatusCode::NOT_FOUND).into_builder(); + return Ok(add_headers(&mut resp).finish()); } }; channel_id @@ -93,6 +98,7 @@ fn channel_route(req: &HttpRequest) -> Result &meta_info.remote ); + // Cannot apply headers here. ws::start( req, session::WsChannelSession { @@ -106,24 +112,50 @@ fn channel_route(req: &HttpRequest) -> Result(resp: &'a mut HttpResponseBuilder) -> &'a mut HttpResponseBuilder { + resp.header( + "Content-Security-Policy", + "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; report-uri /__cspreport__", + ) + .header("X-Content-Type-Options", "nosniff") + .header("X-Frame-Options", "deny") + .header("X-XSS-Protection", "1; mode=block") + .header("Strict-Transport-Security", "max-age=63072000") +} + fn heartbeat(req: &HttpRequest) -> Result { // if there's more to check, add it here. let body = json!({"status": "ok", "version": env!("CARGO_PKG_VERSION")}); - Ok(HttpResponse::Ok() - .content_type("application/json") - .body(body.to_string())) + Ok(add_headers(HttpResponse::Ok().content_type("application/json")).body(body.to_string())) } fn lbheartbeat(req: &HttpRequest) -> Result { // load balance heartbeat. Doesn't matter what's returned, aside from a 200 - Ok(HttpResponse::Ok().into()) + Ok(add_headers(&mut HttpResponse::Ok()).finish()) } fn show_version(req: &HttpRequest) -> Result { // Return the contents of the version.json file. - Ok(HttpResponse::Ok() - .content_type("application/json") - .body(include_str!("../version.json"))) + Ok( + add_headers(&mut HttpResponse::Ok().content_type("application/json")) + .body(include_str!("../version.json")), + ) +} + +/// Dump the "CSP report" as a warning message. +fn cspreport( + req: &HttpRequest, +) -> Box> { + let log = req.state().log.clone(); + req.body() + .from_err() + .and_then(move |body| { + let bstr = str::from_utf8(&body).unwrap(); + warn!(log.log, "CSP Report"; "report"=> bstr); + Ok(add_headers(&mut HttpResponse::Ok()).finish()) + }) + .responder() } fn build_app(app: App) -> App { @@ -140,6 +172,9 @@ fn build_app(app: App) -> App