in
Clone
https://git.tahinli.com/Tahinli/in.git
0 watching0 forksRustAGPL-3.0528.7 KiB9215377Tahinli27 days ago37 commits
| 1 | //! The security headers of every response, and the Content-Security-Policy they carry. |
| 2 | //! |
| 3 | //! The policy allows scripts and styles from the origin itself and nothing else. No page may use an |
| 4 | //! inline script, an inline style or an inline event handler: all behaviour lives in |
| 5 | //! `crates/in-web/assets/*.js`. Changing [`CSP`] is a security change, so keep it in step with |
| 6 | //! `docs/conventions.md` section 5. |
| 7 | |
| 8 | use Cx; |
| 9 | use uri; |
| 10 | use response_headers; |
| 11 | use |
| 12 | |
| 13 | ; |
| 14 | |
| 15 | /// The Content-Security-Policy of every response. |
| 16 | pub const CSP: &str = "default-src 'self'; img-src 'self' data:; style-src 'self'; script-src 'self'; \ |
| 17 | form-action 'self'; frame-ancestors 'none'; base-uri 'none'"; |
| 18 | |
| 19 | /// Path prefix of the public share pages and their bytes. The token is in the path, so these pages send no |
| 20 | /// referrer and ask search engines not to index them (architecture section 8). |
| 21 | pub const SHARE_PREFIX: &str = "/s/"; |
| 22 | |
| 23 | /// `Referrer-Policy` of the public share pages: the token in the URL must never reach another site. |
| 24 | const SHARE_REFERRER: &str = "no-referrer"; |
| 25 | |
| 26 | /// `X-Robots-Tag` of the public share pages. |
| 27 | const SHARE_ROBOTS: &str = "noindex"; |
| 28 | |
| 29 | /// The headers of `base` as they apply to a request for `path`: on a public share path the referrer and |
| 30 | /// robots headers are replaced, everywhere else `base` is used as it is. |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | /// One year, in seconds. Sent only when the public origin is https. |
| 47 | const HSTS: &str = "max-age=31536000"; |
| 48 | |
| 49 | /// The headers that every response carries, for an instance at `base_url`. |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | /// Adds a fixed set of headers to every response of the router. |
| 75 | /// |
| 76 | /// It uses the per-request response headers, which the router applies after the layers have run, |
| 77 | /// so error responses (404, 500) carry them as well. |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 |