Repository navigation
Allow rendering HTML pastes as sandboxed pages - #236
theryecatcher wants to merge 2 commits into
Conversation
Let `.html` and `.htm` pastes be viewed as the page, so self contained
documents with inline CSS, SVG and web fonts can be shared directly
instead of as highlighted source. The feature is optin through
`WASTEBIN_RENDER_UNTRUSTED_HTML`.
- Serve the paste unmodified at `/html/{id}`, toggled from the source
and QR views like rendered Markdown. Burn confirmation and password
prompts post back to the same route, so both kinds of protected paste
work.
- Isolate the page with a CSP `sandbox` and no allow flags. It gets an
opaque origin with no access to wastebin cookies, and scripts, forms and
top level navigation are blocked.
- Let the security headers layer keep a CSP set by the handler, since
this route returns both wastebin pages and sandboxed pastes.
Collate the confirmation flows which returns the paste or the prompt page to show first. Each view now only names the route its prompts post back to. Caching and other pages shown are unchanged.
9e4362c to
c406f83
Compare
matze
left a comment
There was a problem hiding this comment.
I will play further with it, thanks so far! Please also take a look at i18n.rs, paste.help.toggle_rendered is specific to Markdown.
| tracing::debug!("enforcing a http timeout of {timeout:#?}"); | ||
|
|
||
| if render_html { | ||
| tracing::warn!("serving html pastes as sandboxed pages at /html/{{id}}"); |
There was a problem hiding this comment.
Should that be a server-side warning though?
| * <kbd>q</kbd> to display the current URL as a QR code, | ||
| * <kbd>p</kbd> to view the formatted paste, | ||
| * <kbd>w</kbd> to toggle line wrapping on and off (off by default), | ||
| * <kbd>m</kbd> to toggle the rendered view on Markdown pastes and |
There was a problem hiding this comment.
Please make that its own commit and CHANGELOG entry.
| | `WASTEBIN_ADDRESS_PORT` | Address and port to bind the server to. | `0.0.0.0:8088` | | ||
| | `WASTEBIN_BASE_URL` | Base URL for the QR code display. | | | ||
| | `WASTEBIN_CACHE_SIZE` | Number of rendered items to cache. | `128` | | ||
| | `WASTEBIN_RENDER_UNTRUSTED_HTML` | Set to `true` to show `html` and `htm` pastes as sandboxed pages at `/html/{id}`. See [HTML pages](#html-pages) before enabling. | `false` | |
There was a problem hiding this comment.
This breaks order, please move it down.
| Err(VarError::NotUnicode(_)) => Err(Error::RenderHtml), | ||
| Ok(value) => match value.to_ascii_lowercase().as_str() { | ||
| "true" | "1" => Ok(true), | ||
| "false" | "0" => Ok(false), |
There was a problem hiding this comment.
You only document true and false, so drop 1 and 0.
|
|
||
| When `WASTEBIN_RENDER_UNTRUSTED_HTML` is set to `true`, pastes | ||
| created with an `html` or `htm` extension can be viewed as a page of their own | ||
| at `/html/{id}`, reached through the same toggle as rendered Markdown. It is |
There was a problem hiding this comment.
I think the premise that it's based on file extension is a bit flawed because /html/{id} does not check extension.
| // Pastes served as HTML documents carry their own sandbox policy. | ||
| if !headers.contains_key(CONTENT_SECURITY_POLICY) { | ||
| headers.insert(CONTENT_SECURITY_POLICY, csp); | ||
| } |
There was a problem hiding this comment.
This looks a bit iffy to me. Can we make the policy explicit and typed and have the layer write exactly one CSP? So basically an enum Csp { Strict, Rendered, Sandbox } with const fn that returns the appropriate HeaderValue and something like this in this layer:
let mut response = next.run(req).await;
let csp = response.extensions_mut().remove::<Csp>().unwrap_or(Csp::Strict);
let headers = response.headers_mut();
headers.insert(CONTENT_SECURITY_POLICY, csp.header());
for (name, value) in defaults { headers.insert(name, value); }
response|
Thanks for the comments !! I thought to take a look at the translation should have been a simple Google Translate will do that. The rest of the requested changes look straightforward enough will implement them too. The struct was definitely something I should have thought about too. |
I can check the German translation 👍 |
Closes #235
Lets
.htmland.htmpastes be opened as the page, at/html/{id}, so documents with inline CSS, SVG and web fonts can be shared directly instead of as highlighted source. It is off by default and turned on withWASTEBIN_RENDER_UNTRUSTED_HTML=true.Security
/html/{id}are wastebin's own pages and keep the strict policy. To allow that, the security headers layer now keeps a CSP. Only/html/{id}sets it, so every other route should be unchanged./html/{id}returns wastebin's 404 page and no toggle is shown.Testing
All tests (including clippy) pass. Some new tests cover the sandbox, burn and password pastes, missing pastes and the default off behaviour.