Data URI generator and decoder
Turn text or a small file into a data: URI, or decode one to see its media type and content. Explains the risk of data: URIs in a Content Security Policy.
For example text/html, image/svg+xml, application/json.
The result appears here.In a Content Security Policy, the source data: allows every data: URI for that directive. It is common and low risk in img-src and font-src. In script-src, object-src, frame-src or default-src it lets injected markup bring its own script, which defeats the policy.
Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.
How to use the data URI generator and decoder
- Choose text to data URI, file to data URI, or decode.
- For text, set the media type and choose Base64 or percent-encoding.
- For a file, choose one of up to 1 MB. It is read in your browser.
- Copy the URI, or read the media type and content of a decoded one.
About this tool
A data: URI carries a file inside the URL itself: the scheme, a media type, an optional ;base64 marker, a comma, and the content. data:text/plain;base64,SGVsbG8= is a complete text file that says Hello. They are used to inline small images and fonts in CSS, to embed an icon in a single HTML file, and in email, so that nothing has to be fetched separately.
This tool builds one from text or from a file you choose, read in your browser, and decodes one back into its media type and content. Base64 makes content a third larger, and an inlined file cannot be cached separately from the page that holds it, so data: URIs suit files of a few kilobytes. For text, percent-encoding is often shorter and stays readable, and you can pick either.
They matter for security because the content can be a document or a script. A data:text/html URI is a whole page, and an SVG can carry script, which is why browsers block top-level navigation to data: URLs and phishing kits still try them. In a Content Security Policy, allowing data: in script-src, object-src or default-src lets injected markup supply its own code. The decoder shows content as text or bytes and never runs it.
Sources
Questions
A URL that contains the data itself, not the address of it. It starts with data:, names a media type such as image/png, and holds the content as Base64 or percent-encoded text. Browsers treat it like a file of that type.
Choose the file here and copy the result, or on a command line run base64 on the file and put data:image/png;base64, in front. Use the URI as the src of an img tag or inside url() in CSS.
In img-src and font-src it is common and low risk. Avoid it in script-src, object-src, frame-src and default-src, where it lets an attacker who can inject markup run script from a data: URI and so defeats the policy.
They can be. A data: URI with an HTML or SVG type is active content, and it has been used for phishing pages that show no real address. Treat one from an untrusted source like any unknown file: decode and inspect it, do not open it.
Browsers accept several megabytes, but that is rarely a good idea. The content grows by a third in Base64, blocks the page that contains it and cannot be cached by itself. Keep them for small assets.