Skip to content

Allow rendering HTML pastes as sandboxed pages - #236

Open
theryecatcher wants to merge 2 commits into
matze:masterfrom
theryecatcher:master
Open

theryecatcher wants to merge 2 commits into
matze:masterfrom
theryecatcher:master

Conversation

@theryecatcher

Copy link
Copy Markdown
Contributor

Closes #235

Lets .html and .htm pastes 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 with WASTEBIN_RENDER_UNTRUSTED_HTML=true.

Security

  • The paste is served under a CSP sandbox with no allow flags. The page has an opaque origin with no access to wastebin cookies, and scripts, form submissions and top level navigation are blocked.
  • Burn confirmation and password prompts on /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.
  • When it's off /html/{id} returns wastebin's 404 page and no toggle is shown.
  • I also pulled the burn and password prompt flow, which the source, Markdown and HTML views each repeated, into one shared helper.

Testing

All tests (including clippy) pass. Some new tests cover the sandbox, burn and password pastes, missing pastes and the default off behaviour.

@theryecatcher
theryecatcher marked this pull request as draft November 23, 2026 04:55
@theryecatcher theryecatcher reopened this Nov 23, 2026
@theryecatcher
theryecatcher marked this pull request as ready for review November 23, 2026 04:58

@matze matze left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/wastebin_server/src/main.rs Outdated
tracing::debug!("enforcing a http timeout of {timeout:#?}");

if render_html {
tracing::warn!("serving html pastes as sandboxed pages at /html/{{id}}");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that be a server-side warning though?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed it's not an abnormal condition, so I moved it to debug with the other startup settings. If you meant a warning for viewers instead, we could add it as a console log but unsure if that will help in any situation. Happy to add one if you think it's worth it.

Comment thread README.md Resolved
Comment thread README.md Resolved
Comment thread crates/wastebin_server/src/env.rs Resolved
Comment thread README.md Resolved
Comment thread crates/wastebin_server/src/main.rs Resolved
@theryecatcher

Copy link
Copy Markdown
Contributor Author

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.

@matze

matze commented Nov 25, 2026

Copy link
Copy Markdown
Owner

I thought to take a look at the translation should have been a simple Google Translate will do that.

I can check the German translation 👍

Let pastes be viewed as the page itself at `/html/{id}`, so self
contained documents with inline CSS, SVG and web fonts can be shared
directly instead of as highlighted source. The feature is opt-in through
`WASTEBIN_RENDER_UNTRUSTED_HTML`.

- Serve the paste unmodified under a CSP `sandbox` with no allow flags.
It gets an opaque origin with no access to wastebin cookies, and
scripts, forms, pop-ups and automatic redirects are blocked.
- Show a toggle to the page on `html` and `htm` pastes.
- Have handlers return a typed `Csp` that the security headers layer
writes as the only policy, defaulting to strict. As a side effrct
Markdown burn, password and error pages now get the strict policy too.
- Share the burn confirmation and password prompt flow across the
source, Markdown and HTML views, so each view only names the route its
prompts post back to.
The m key clicks the view toggle, which HTML pastes now have too, so it
opens their sandboxed page. No wastebin script runs on that page, so m
cannot toggle back.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rendering HTML pastes as standalone pages

2 participants