Skip to content

Commit

Permalink
feat: add CORS access control header to the API
Browse files Browse the repository at this point in the history
Fix #118.
  • Loading branch information
Kyle Clemens committed Jun 12, 2019
1 parent f4f6955 commit fa908ee
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion webserver/src/routes/web/fairings/security_headers.rs
Expand Up @@ -15,10 +15,14 @@ impl Fairing for SecurityHeaders {
}
}

fn on_response(&self, _: &Request, resp: &mut Response) {
fn on_response(&self, req: &Request, resp: &mut Response) {
resp.set_header(Header::new("X-Frame-Options", "DENY"));
resp.set_header(Header::new("X-XSS-Protection", "1; mode=block"));
resp.set_header(Header::new("X-Content-Type-Options", "nosniff"));
resp.set_header(Header::new("Referrer-Policy", "strict-origin-when-cross-origin"));

if req.uri().path().starts_with("/api/") {
resp.set_header(Header::new("Access-Control-Allow-Origin", "*"));
}
}
}

0 comments on commit fa908ee

Please sign in to comment.