IABrowseStop
Menu

Journal

Three doors, and the one everybody forgets

Blocking the file picker leaves two doors open. The third does not even require leaving the keyboard.

When you set out to stop a file being uploaded from a browser, the first instinct is to deal with the Browse button. It is the visible route, the one you picture when you think about an upload.

There are three.

First door: the file picker

This is the <input type="file">. The user clicks, a system dialog opens, they pick a file, the field fills in.

It is the best-known route and the easiest to watch — on one condition: that the field exists at the moment you look. In a modern web application it is often created on click, inside a component loaded later, sometimes in a nested frame. A guardrail that inspects the page once, at load, will never see it.

Second door: drag and drop

The user grabs a file from their desktop and drops it into the conversation. No field is involved: it is a drop event, with the files attached to the transfer object.

The trap here is the target area. Many interfaces accept a drop anywhere on the page, not only in the dashed rectangle that advertises it. Watching the visible area is therefore not enough; you have to watch the page.

And you have to do it before the application does: intercept too late and the application has already read the file.

Third door: the clipboard

This is the one that gets forgotten.

The user copies a file — from the file manager, from an email attachment, from a screenshot they have just taken — and pastes it into the conversation. Two keyboard shortcuts, no dialog, no button.

Technically the paste event carries files, exactly as the drop does. Functionally it is the fastest and least visible of the three routes. A guardrail that does not cover it leaves a way around that anybody discovers by accident, simply working normally.

There is one more subtlety: the paste event targets the focused element, or the document body. It does not travel down to the drop zone. The listener therefore has to be global — while leaving text inputs alone, where pasting text is perfectly normal.

What that implies for implementation

Closing all three doors, in practice, takes four things:

  • Be there at the very start of document load, not after. A script injected too late sees a page already built and listeners already attached.
  • Be there in every frame, not only the top one. Upload interfaces often live in a nested frame.
  • Listen in the capture phase, to intercept before the application rather than after it.
  • Observe document mutations, to cover controls inserted after load — which is to say most of them.

None of these four requirements is exotic. Together they are the difference between a guardrail that works in a demo and a guardrail that works on a real application.

Refusing without reading

None of this requires knowing what the file holds.

To decide, it is enough to know which service the upload is going to, and whether the policy allows that kind of file to that service. The kind is read from the name’s extension — three or four characters, in memory, for the length of one display.

It is very little, and it is enough. It is also what makes the thing defensible in front of a data protection officer: there is no content to protect, because there is no content read.

And if the policy has not answered

A guardrail that lets things through while it initialises is not one. The right default is refusal: refuse until the policy has answered, refuse if the list of allowed extensions is empty, refuse if loading the policy failed.

In other words: fail shut. It is the only posture that holds, because a loading error is precisely the moment you would least like to be open.