Skip to content

Commit

Permalink
Serve more static files from nginx
Browse files Browse the repository at this point in the history
Serve more folders containing files with hashed filenames directly from
nginx with a max expiration date.  Additionally, some unhashed static
files are allowed to be cached for up to 1 day.

These changes serve as a workaround for an authentication issue.
Currently `conduit-cookie` includes a `Set-Cookie` header in every
backend response.  During the authentication steps, the popup window
requests static assets such as `favicon.ico` and `cargo-{hash}.png`.
If these assets are served by the backend, they will echo whatever
cookie was sent in the request.  Therefore, there is a race between the
request to `/api/private/session/authorize?...` and requests for these
static assets.  If a request for one of these assets is sent before
authorization is complete and the response arrives after successful
authorization, then the stale cookie will be stored again by the
browser, overwriting the contents.

I've opened conduit-rust/conduit-cookie#12 to track the progress of the
proposed long-term solution.  This commit should be sufficient to fix
the behavior for now and should reduce the number of requests for these
static assets (due to improved caching).

Closes #2252
r? @carols10cents
  • Loading branch information
jtgeibel committed Apr 2, 2020
1 parent 8c1a7e2 commit 45c7511
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion config/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,27 @@ http {
server_name _;
keepalive_timeout 5;

location ~ ^/assets/ {
location ~ ^/(assets|ember-fetch|moment)/ {
add_header X-Content-Type-Options nosniff;
add_header Cache-Control public;
root dist;
expires max;
}

location ~ ^/cargo-[0-9a-f]*\.png$ {
add_header X-Content-Type-Options nosniff;
add_header Cache-Control public;
root dist;
expires max;
}

location ~ /(favicon\.ico|robots\.txt|opensearch\.xml) {
add_header X-Content-Type-Options nosniff;
add_header Cache-Control public;
root dist;
expires 1d;
}

add_header X-Content-Type-Options "nosniff";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
Expand Down

0 comments on commit 45c7511

Please sign in to comment.