Abbi Labs

Guides

Can an uploaded SVG or HTML file run JavaScript on your site? File upload XSS in AI-built apps

By Abbi Labs · Last updated 2 December 2026

Scan your app free and see what your live site exposes.

Abbi Labs checks your security headers (including a missing or weak Content-Security-Policy), secret keys in your JavaScript, Supabase tables readable with your public key, exposed .env and .git files, source maps, CORS, cookie flags and TLS. Read-only. No sign-up for the quick check.

No app handy?

Example result · our deliberately broken demo app

6 issues found: 3 critical, 1 high, 1 medium, 1 low

  • Critical: Stripe live secret key in public JavaScript
  • Critical: /.env file readable by anyone
  • High: Git repository exposed (/.git/HEAD)

The demo's problems are planted on purpose. Paste your own URL above to see yours.

No sign-up. Read-only public-resource and protocol metadata checks. No model prompts or tool execution. Scan only sites you own or are allowed to test.

Run on every deploy or use from Cursor / Claude Code via MCP →

Weekly AI-app security checklist

One short email a week: a practical check for apps built with Supabase, Next.js and AI tools (RLS, leaked keys, headers and more). Unsubscribe anytime.

Your app lets people upload an avatar, a logo or an attachment. The AI builder wired up the upload, the file shows up, job done. The question nobody asks is what happens when someone uploads an SVG with a <script> inside it, or an HTML file, and then sends a friend the direct link.

Sources for the facts below: Supabase Storage's security policy and bucket docs, Vercel's Blob public storage docs, and web.dev's securely hosting user data.

Why an image can run code

SVG isn't a picture format like PNG. It's an XML document, and it can contain <script> tags and onload attributes. Two things decide whether that script runs:

HTML uploads are the same problem with fewer steps. Any file served as text/html from your domain is a page on your site that a stranger wrote.

Where you're already covered, and where AI-built apps lose it

Check yours in 3 minutes

  1. Find your upload code. Search the project for storage.from(, createBucket, allowedMimeTypes, multer, express.static, put( (Vercel Blob) and any route that returns file bytes. Note where uploaded files are served from: storage's own URL, or your domain.
  2. Read the headers on a real upload. Take the URL your app uses for an uploaded file and run:
    curl -sI "https://yourapp.com/uploads/some-file.svg" | grep -iE "content-type|content-disposition|content-security-policy|x-content-type-options"
    Red flag: image/svg+xml or text/html served from your own domain with no Content-Disposition: attachment and no CSP.
  3. Try it on your own app. Save this as test.svg, upload it through your app as a normal user, then open the file's URL in a new tab:
    <svg xmlns="http://www.w3.org/2000/svg" width="200" height="60">
      <text x="10" y="35">upload test</text>
      <script>alert('script ran on ' + document.domain)</script>
    </svg>
    If an alert shows your app's domain, an attacker can do the same with a script that isn't an alert. If the upload was rejected, the file downloaded, or no alert appeared, that path is fine. Repeat with a small test.html if your app accepts any file type. Only test apps you own.

The fix

1. Allow only the types you need, on the server. The accept attribute on a file input is a convenience, not a control. For Supabase, set allowed MIME types and a size limit on the bucket (Dashboard, Storage, bucket settings, or in code), and list exact types. Note that image/* lets image/svg+xml through:

// run once from a server script with the service_role key (never in the browser),
// or set the same values in the dashboard
await supabase.storage.updateBucket('avatars', {
  public: true,
  allowedMimeTypes: ['image/png', 'image/jpeg', 'image/webp'],
  fileSizeLimit: '2MB',
})

For multer, check the type in fileFilter, and remember file.mimetype is what the uploader claims. Save files under a name and extension you choose, not the one they sent.

2. Don't serve uploads from your app's domain. Link to the storage URL (Supabase, Blob, a bucket) instead of proxying. If you do need your domain, for example to check permissions before a download, set the headers yourself. web.dev recommends this set for user files:

// Next.js route handler returning a stored file
return new Response(body, {
  headers: {
    'Content-Type': 'application/octet-stream', // or the exact safe type, e.g. image/png
    'Content-Disposition': 'attachment; filename="download"',
    'X-Content-Type-Options': 'nosniff',
    'Content-Security-Policy': "default-src 'none'; sandbox",
  },
})

// Express
app.use('/uploads', express.static('uploads', {
  setHeaders(res) {
    res.set('Content-Disposition', 'attachment')
    res.set('X-Content-Type-Options', 'nosniff')
    res.set('Content-Security-Policy', "default-src 'none'; sandbox")
  },
}))

3. If users really need SVGs, show them only through <img>, convert them to PNG on upload, or sanitise them (DOMPurify has an SVG profile) before they're stored. Then clean up: search your bucket or uploads folder for existing .svg, .html and .xml files you didn't expect.

Paste this into your AI builder

Review how this app handles user file uploads.
1. List every upload path and where each file is served from
   (storage URL or our own domain).
2. Restrict uploads server-side to exact types we need (for example
   image/png, image/jpeg, image/webp). No image/*, no SVG or HTML
   unless I confirm we need them. Set a size limit.
3. Any route on our domain that returns uploaded files must send
   Content-Disposition: attachment, X-Content-Type-Options: nosniff
   and Content-Security-Policy: default-src 'none'; sandbox.
4. Display user images only through <img> tags.
5. Tell me which existing uploaded files are SVG, HTML or XML.

What Abbi Labs checks

Honest scope: the scan never uploads files and doesn't fetch your users' uploads, so it can't tell you whether this specific hole is open. Run the test above for that. What it does check: the free quick check reads your home page headers and flags a missing Content-Security-Policy or a weak one (unsafe-inline without a nonce or hash, unsafe-eval, wildcard script sources), which decides how much an injected script can get away with. The full scan on a verified domain also lists your Supabase storage buckets with the public key and flags any marked public, which is the other half of upload safety (who can read your files).

Scan your app free

FAQ

Can an SVG file contain JavaScript?

Yes. SVG is an XML document format and can include <script> elements and event handler attributes like onload. When a browser shows an SVG through an <img> tag it doesn't run those scripts. When someone opens the SVG's URL directly, the browser treats it as a document and the scripts run on whatever origin served it.

Are Supabase Storage uploads safe from this?

On hosted Supabase, mostly yes by default. Supabase Storage's security policy says the hosted platform serves HTML as plain text and serves SVG as a download with a restrictive Content-Security-Policy and X-Content-Type-Options: nosniff, and the files live on your project's supabase.co address, not your app's domain. You lose that protection if your app proxies files back through its own domain and copies the content type without those headers. On self-hosted Supabase, check what headers your gateway adds.

Does allowedMimeTypes: ['image/*'] block SVG?

No. SVG's type is image/svg+xml, so a wildcard image/* allows it. List the exact types you need, for example image/png, image/jpeg and image/webp.

Is the accept attribute on my file input enough?

No. accept="image/png" only filters the file picker. Anyone can send any file straight to your upload endpoint or the Storage API. The restriction has to live on the server or the bucket.

What can a script in an uploaded file actually do?

If it runs on your app's domain, it runs as your site in the victim's browser. It can read anything your front end keeps in localStorage (supabase-js keeps the browser session there by default) and call your API as whoever opened the link.

My app needs to show user SVGs. What then?

Only display them through <img> tags, never link to the raw file on your domain, and serve the files from a separate domain with Content-Disposition: attachment. Converting uploads to PNG on the server, or sanitising them with a library like DOMPurify's SVG profile, removes the scripts before they're stored.

Does Abbi Labs check this?

Not directly. The scan never uploads files and doesn't fetch your users' uploads. The free quick check (no sign-up) reads your home page headers and flags a missing or weak Content-Security-Policy, which limits what an injected script can do. The full scan on a verified domain also lists your Supabase storage buckets with the public key and flags any marked public. The upload test on this page is one you run yourself.

Related guides

Weekly AI-app security checklist

One short email a week: a practical check for apps built with Supabase, Next.js and AI tools (RLS, leaked keys, headers and more). Unsubscribe anytime.