pushbag
Developer blog

How pushbag serves untrusted HTML

10 min read

Published · Updated

Pushbag gives each artifact its own hostname and serves uploaded HTML under a sandbox Content-Security-Policy. For a public report, you can inspect the raw response without running any of the uploaded code:

artifact_url=$(pushbag upload report.html --public) && curl -sSI "$artifact_url"

Look for Content-Security-Policy, X-Content-Type-Options: nosniff, and X-Pushbag-Version. The last header identifies the version selected by the server. The root path resolves to the current version, while /v/N selects a numbered version. Versions share an origin with each other. Two different artifacts have different hosts, even if the same person published them.

Admission and execution are separate decisions

On upload, the HTML policy checks the document before publication. Among other things it refuses forms, embedded documents, external scripts and external stylesheets. A refusal leaves the publisher with an error to fix. The service does not turn a rejected document into a different one by silently removing markup.

A separate pass inspects inline scripts and event handlers. A document with no executable script is classified as none. Admitted scripts without flagged findings are interactive. Findings such as a password field in a scripted document can produce a suspicious classification and a warning in the viewer. Some findings reject the upload outright. Classification decides which viewing experience to offer. Browser restrictions still apply to admitted code.

A raw document and a browser view take different paths

The raw HTML policy starts with default-src 'none'. It allows inline styles and HTTPS or data images and fonts. Its sandbox allows popups and omits permission to run scripts. A scriptless report can render this way directly. A command-line reader can retrieve the source of a scripted report under the same policy.

For a scripted version opened as a top-level browser document, the server sends its own wrapper. The wrapper owns the warning and report controls for suspicious content. It places the upload inside an iframe with sandbox="allow-scripts". Omitting allow-same-origin gives the framed document an opaque origin, separating its code from the wrapper.

The frame response also sets its own CSP. Its script sources include SHA-256 hashes of the admitted code and the viewer bootstrap. The frame allows inline styles, data or blob images and media, and data fonts. It sets connect-src 'none'. For example, a chart can redraw itself from data embedded in the report, but its script cannot fetch a fresh series from an API.

Access can change between the two requests

The wrapper issues a short-lived signed token scoped to the selected version and viewer. When loading the frame, the server checks the token, the version’s association with the artifact, and the current access decision before reading the stored document. That second check matters if the owner deletes the artifact or changes its visibility after the wrapper was served.

The wrapper response varies on the browser’s fetch destination and carries private cache controls because it contains a token. Private document responses also vary on the cookie and grant header used for access. For publication and review examples, see privacy and versions and sharing a report.

What the upload worker actually checks

Consider a report with a Mermaid chart and a button that expands a table. The CLI can inspect both from the author’s working directory and return a useful error before sending bytes. But the HTTP API also accepts uploads. Trusting the CLI’s verdict would make the choice of client part of the security boundary. Finalization in packages/business/src/uploads/finalize.ts decodes the uploaded HTML as UTF-8 with fatal decoding errors, then makes three separate calls:

const mermaid = renderMermaidBlocks(html);
const policy = evaluateHtmlPolicy(mermaid.html);
const scripts = classifyScripts(mermaid.html);

The order matters. A renderer can introduce attributes and links that weren’t literal HTML in the source. The policy sees the rendered figure that a browser will receive. The size check also considers the rendered bytes. A small diagram description doesn’t entitle its publisher to serve an arbitrarily large generated SVG. If the CSS was supplied as an external stylesheet, the policy reports External stylesheet <link> elements are not allowed. That feedback lets the report author fix the source and regenerate the same design.

The script pass parses executable text and examines its syntax tree. It looks at both script elements and inline event handlers. It collects declarations so that a reference can be interpreted in context. A chart using ordinary DOM operations and a page requesting a password don’t present the same cues to a reader, even if neither document needs network access. The latter can trigger a finding when it contains script. A rejection is a different outcome: the upload never becomes a ready version. The server includes the findings in the policy error so a publisher can locate the affected line.

For an accepted scripted page, finalization stores the tier, findings and CSP hash sources for the rendered version. A stored hash describes which bytes the browser may execute. It does not establish the author’s identity or certify the calculation in a chart. That distinction explains why the worker still isolates an interactive document even after static analysis has completed.

Read the headers as three separate policies

For raw HTML the following is the complete value of Content-Security-Policy. The service sets Content-Disposition: inline, Content-Type: text/html; charset=utf-8, Referrer-Policy: no-referrer, and X-Content-Type-Options: nosniff. Selecting the response MIME type on the server keeps an upload’s claimed type out of this decision.

default-src 'none'; img-src https: data:; style-src 'unsafe-inline'; font-src https: data:; form-action 'none'; frame-ancestors 'none'; base-uri 'none'; sandbox allow-popups

The default denies resource loads unless a more specific directive opens them. Styles can be written in the document. Images and fonts can use HTTPS or embedded data. There is no script exception. Form submission has its own explicit denial, and other sites cannot embed this response in a frame. A base element cannot change the URL against which links resolve. The sandbox permits popups so ordinary outward links can work. A consequence of the image and font allowances is that opening a raw report can contact an external asset host. Inline those assets when that request itself would disclose information.

The scripted frame gets the directives below. They are shown one per line for readability. In the actual header the worker joins them with semicolons and replaces the angle-bracketed fields with quoted SHA-256 sources for the exact scripts. The set of hashes varies by version.

default-src 'none'
script-src <bootstrap-hash> <version-hashes> 'unsafe-hashes'
style-src 'unsafe-inline'
img-src data: blob:
media-src data: blob:
font-src data:
connect-src 'none'
form-action 'none'
base-uri 'none'
frame-src 'none'
worker-src 'none'
frame-ancestors 'self'
sandbox allow-scripts

Here the image allowance is narrower than on the raw response. A chart inside the frame can display embedded pixels or a locally generated blob. Remote images and fonts are unavailable. The hash list admits the inspected script bodies, and the unsafe-hashes keyword allows matching handler hashes. The frame cannot create another frame or start a worker. Its parent must match the allowed ancestor. The response repeats the sandbox restriction independently of the iframe attribute. Local UI code can execute without gaining an origin it could share with its parent.

The wrapper in turn defaults to denying loads, authorizes its own script and stylesheet by hash, sets frame-src 'self' and connect-src 'self', and allows only data images. It denies form actions, base URLs and frame ancestors. This lets the service’s page display its child and submit a report on the same host. On a suspicious page, the warning and outbound destination dialog live in this parent. Text drawn inside the report cannot edit the actual parent controls. The wrapper checks the sending window and the destination scheme before handling a navigation message.

A public hostname is an address, not an access credential. For a private artifact, the owner can open the ordinary link with a qualifying signed-in session. An owner can also run pushbag open ARTIFACT_ID to mint a temporary view URL. The default view grant lasts one hour. Someone receiving it doesn’t need to sign in as the owner. This is an intentional delegation, so forwarding the full URL delegates the same access again during that interval.

The content worker accepts a grant in the query or in X-Pushbag-Grant. It verifies the signature, expiry and content audience, then matches the artifact ID and any version restriction. A valid match supplies the owner identity used in the access decision. Grant verification precedes session fallback so that a recipient already signed in to their own account can still open the owner’s link. A Notifications key alone cannot stand in for the owner’s artifact credential.

Current state still lives in the database. For private content the policy checks the viewer against the owner before explaining whether a version is disabled, deleted, or expired. A fixed expiry applies at request time even if the cleanup job hasn’t swept the object yet. When the wrapper needs its frame, the service creates a different signed token with a ten-minute lifetime. It names the selected version and carries the viewer identity for the second access check. An expired frame token yields HTTP 403 and the text This view has expired. Reload the page to see it again. Reloading the artifact asks the service to authorize a new view.

Even public version URLs use Cache-Control: public, max-age=0, must-revalidate. The version’s contents can stay the same while access to them changes. A cache may reuse a representation after revalidation, including an ETag check. Private raw documents use Cache-Control: private, no-store and vary on range, cookie and grant header. Scripted raw responses additionally vary on fetch destination, since a top-level browser navigation receives the wrapper. A wrapper always uses the private cache policy, including for a public upload, because it contains a freshly signed frame token.

What to test in your own report

Start with a scriptless report whose only control is a native details element. Inspect the headers with the command above, then open the same URL on your phone. Next add an inline button that sorts a table of embedded values and publish a new version. Inspect the top document and the child response in browser developer tools. The hash-based script policy belongs to the child running the chart. Inspecting only the top document will show you the hashes of the service’s viewer instead.

These boundaries constrain code execution and access to stored bytes. They cannot tell whether the numbers in a report came from a real test, whether a link leads to a trustworthy destination, or whether the reader should act on its instructions. Changing visibility controls future requests. It cannot retrieve a screenshot or a saved copy from someone who already had access. Choose the audience at publication time and keep any long-lived evidence you need outside the viewing session. Report publication · Static host comparison

Frequently asked questions

Do two versions of a report get different browser origins?

No. The hostname identifies the artifact. Numbered versions live at paths under the same hostname.

Why can curl see inline JavaScript in an upload?

The raw response preserves the document source. Its response policy disables script execution in a browser.

Why does a public numbered URL still require cache revalidation?

Visibility and deletion belong to the artifact and can change after a version was published.

Does a private view grant give a reader editing rights?

No. Its audience is the content service, and management access is checked separately.