Dev.to Security 🔐 Cybersecurity 👁 0 📖 16 min read

I Looked at My Clipboard and Found an Address I Never Copied

This morning, hunting for something to write about, it occurred to me to look at my clipboard. I have no idea how many times a day I hit Cmd+C — hundreds, I would guess — but I had never checked what that key actually mo

This morning, hunting for something to write about, it occurred to me to look at my
clipboard. I have no idea how many times a day I hit Cmd+C — hundreds, I would
guess — but I had never checked what that key actually moves around inside the
machine. Not looking inside something you have leaned on for years is a bit
like never opening a cupboard in your own kitchen.

An image was waiting there. That part I expected. Knowing roughly what is on your
clipboard is like knowing roughly what is in your pocket: not exact, but close
enough. What I did not expect were the three other things sitting next to that
image:

public.png                               209,670 bytes
public.html                                  178 bytes
org.chromium.internal.source-rfh-token        24 bytes
org.chromium.source-url                      115 bytes

That fourth line is a 115-byte address beginning with https. So when an image
lands on my clipboard, where it came from lands there too. I am not printing the
address here; the whole point of this piece is that it is sitting there without my
having chosen it.

What sits on the clipboard is not a value, it is a bundle

In my head the clipboard had always been a single box: you put something in, you
take it out. The reality is different. The clipboard is not a box, it is a bundle
carrying both translations of the same content into different languages and a label
saying where that content came from
. I put one thing into the bundle; not
everything that comes back out is mine.

The types the item says it carries — "supports", in Apple's wording,
NSPasteboardItem.types — are the four lines above. The list for the whole
pasteboard, NSPasteboard.types, returns eight: four of them extra. The four extras were Apple PNG
pasteboard type
, Apple HTML pasteboard type, NeXT TIFF v4.0 pasteboard type and
public.tiff. Those last two are the interesting ones, because nobody ever put a
TIFF on that clipboard. Yet when I asked for it, it arrived: 766,652 bytes.

AppleScript's clipboard info goes further still: ten rows — nine image formats and
HTML — totalling 2,772,006 bytes. Thirteen times the 209,987 bytes that were
actually handed over.

Apple's documentation for types describes the list as the union of the types
"declared" for the pasteboard's items, returned in the order they were declared.
Declared, says the documentation. Not by me, that much is certain. Somewhere in
between, someone is speaking on my behalf.

Two of the four extras are aliases, two are conjured

Lumping all four extras together would have been sloppy, so I asked each one how
many bytes it would hand over. The table explains itself:

Extra type Data returned Declared counterpart
Apple PNG pasteboard type 209,670 bytes public.png — byte-for-byte identical
Apple HTML pasteboard type 178 bytes public.html — byte-for-byte identical
NeXT TIFF v4.0 pasteboard type 766,652 bytes none
public.tiff 766,652 bytes none

The first two are aliases. Their byte counts match the declared types exactly: the
same data, also offered under its old Cocoa name — thirty years of compatibility
debt, visible on the clipboard. I have no objection to that; I rather like it. A
name from the NeXT world of the 1990s still answers on a 2026 Mac.

The last two are something else. No TIFF was ever handed to the pasteboard, both
names return the same 766,652 bytes, and those bytes are not a copy of any declared
representation. Someone promised, without being asked, "I can give you a TIFF as
well." Who pays for that promise is the next measurement.

Those two types are documented in Chromium's own source

The first time org.chromium.source-url showed up, I wanted to guess what it was.
Just as well I did not, because a technical sentence written from a guess is usually
wrong. Chromium's source settles it. Line 49 of
ui/base/clipboard/clipboard_constants_mac.mm defines the constant:

NSString* const kUTTypeChromiumSourceUrl = @"org.chromium.source-url";

The comment in the header file says what it is for in a single line: a type used to
track the source URL of data put in the clipboard. The browser, in other words,
staples a provenance label to whatever I copy.

The second one, the 24-byte org.chromium.internal.source-rfh-token, is produced in
content/public/browser/clipboard_types.cc. The function is called
SourceRFHTokenType and uses exactly that name on Apple platforms; the surrounding
code deals with ClipboardEndpoint and render_frame_host(). Roughly: an internal
marker for which frame put the content on the clipboard.

Neither type is malicious in intent. To enforce data-loss-prevention policies a
browser has to carry the answer to "where did this come from". My objection is not
to the purpose; it is to who gets to see that label afterwards. The clipboard is a shared
table that programs running under my user on this machine come to; the label is lying
on it. At the end of October, counting
how many of my extensions could read every site,
I was looking at the same table.

One more detail: I looked at the 178-byte HTML representation too. It contains an
<img> tag, its alt text, and a 71-byte address. That address is not the 115-byte
one in the provenance field — it is not even on the same host. One is the page's
address, the other the image's own. So there is no single label on the clipboard:
there are at least two addresses I did not write, inside two separate
representations. Deleting one of them would not be enough.

One format went in, nine came out

The item on my clipboard was a found observation, not an experiment — and nothing in
it says when it was copied, since none of the four types carries a date. So I put the same situation together from scratch. I generated an 800x600 flat-colour PNG — being a
single colour, it compressed down to 10,098 bytes — and declared exactly one type
to the pasteboard:

let item = NSPasteboardItem()
item.setData(png, forType: .init("public.png"))
NSPasteboard.general.clearContents()
NSPasteboard.general.writeObjects([item])

Then I asked the same three questions:

Who asks Answer
NSPasteboardItem.types 1 type (public.png, 10,098 bytes)
NSPasteboard.types 4 types (aliases + public.tiff)
AppleScript clipboard info 9 formats, 3,962,016 bytes total

Data amounting to 392 times the single format I
declared had become "available" without my writing a byte of it. Here is the
breakdown, so you can redo the arithmetic:

PNGf  10,098   AVIF   1,090   8BPS  77,610   GIF    1,563   jp2      484
JPEG   9,115   TIFF 1,920,900   BMP 1,920,138   TPIC 21,018   total 3,962,016

Ninety-seven percent of that total sits in two rows: TIFF and BMP, two uncompressed
copies of the same 800x600 image.

Diagram

The real question is when those bytes come into existence. I asked for
public.tiff: 1,920,900 bytes, delivered in 0.006 seconds. I asked for public.png
in the same breath: 10,098 bytes, too fast to time. 800x600x4 comes to exactly 1,920,000 bytes;
the figure on the clipboard was 1,920,900. The extra 900 bytes are the TIFF's own
header. So that image was produced, uncompressed, at the moment of asking.

Better still: while clipboard info was running, an error line landed in my
terminal.

*** Error creating a JP2 color space: falling back to sRGB

A JPEG 2000 encoder tried to set up a colour space inside the process I had
launched, failed, and fell back to sRGB. In other words, the cost of asking "what is
on the clipboard?" is paid by whoever asks. In time that cost is small — 0.07
seconds with text on the clipboard, 0.12 seconds with the PNG. In bytes it is not.

That 392x figure should not be generalised, because the ratio depends on the content:
my flat-colour PNG compresses absurdly well, which makes the gap look wild. For the real image sitting on my clipboard the same nine image
formats, together with HTML as a tenth row, came to 13.2 times the declared size. Same mechanism, different multiplier.

Who adds the extras?

I could have left it at "someone is speaking on my behalf", but writing about a
mechanism without naming it would break my own rule. There are two candidates:
compatibility types that AppKit adds at write time, or the filter services Apple
documents — the page for NSPasteboard.types(filterableTo:) says it returns the
types that "can be converted to the specified type using the available filter
services".

Two more experiments separate them. First I put the same PNG bytes on the clipboard
under a made-up type (com.example.ozel-tip) instead of public.png:

item.types       = com.example.ozel-tip
pasteboard.types = com.example.ozel-tip

One type. No alias, no TIFF, nothing. Identical bytes, different label — and the
surplus vanished entirely. So the pasteboard is not looking at the content, it is
looking at the name of the type. Plain text behaves similarly: only the
NSStringPboardType alias is added, with no conversion.

Then I asked the filter services directly:

NSPasteboard.types(filterableTo: .tiff) = public.tiff

All that came back was the target itself. Apple's own note makes that easy to read:
"The array also contains the original type." So a single-element answer means there
is nothing else that could be converted. On this machine there is no registered
filter service converting anything to TIFF, so public.tiff showing up in the list
does not come from there. One explanation is left: when a known image type is
written, AppKit declares the TIFF family on my behalf, and produces the bytes only
when they are asked for. That fits Apple's wording for types — the union of
declared types. Declared by someone. Not by me.

I took the made-up-type experiment one step further and ran clipboard info against
that same clipboard. It came back empty: not nine formats, not one. Identical
bytes, the only difference being the name of the label. So there are two separate
layers here — AppKit's pasteboard list and AppleScript's conversion layer — and
neither looks at the content; both look at the name of the declared type. What puts
the provenance label there is something else — Chromium's own write path — but it
leads to the same door: I am not the one deciding what goes into the bundle. I asked
for neither the surplus nor the label.

Even two bytes of text become four representations

In case images were a special case, I tried plain text. I put a two-byte word on the
clipboard with pbcopy. Types declared by the item: one
(public.utf8-plain-text). NSPasteboard.types: two, with the old
NSStringPboardType alias added. clipboard info: four formats — utf8 2 bytes,
ut16 6 bytes, string 2 bytes, Unicode text 4 bytes.

Two bytes in, fourteen bytes sitting there in four different costumes. Nothing scary
about it — what caught my attention was what the list does not contain: on a
plain-text clipboard there is no provenance field at all. No org.chromium.source-url,
no token. The label rides on rich representations; it does not ride on plain text.
That is the measured reason behind the "paste as plain text" advice at the end of
this piece.

The counter: copying leaves a trace, reading does not

The clipboard also has a counter. Apple's documentation says changeCount starts at
zero and increments each time pasteboard ownership changes. The documented purpose is
innocent — so you can tell whether you still own what you put there.

I checked two things.

First, I read the clipboard twenty times in a row. The counter read 893 before, and
893 after. Reading leaves no trace at all. "Who read my clipboard" has no answer
in that number.

Second, I ran a watcher for six seconds that polled nothing but the counter and never
touched the content. I copied three times while it ran. It caught all three:

watcher started, changeCount=890
2.21 s: CHANGED 890 -> 891 (content not read)
2.83 s: CHANGED 891 -> 892 (content not read)
3.44 s: CHANGED 892 -> 893 (content not read)
copy events caught in 6 seconds: 3

So noticing that I copied something requires no access to my clipboard's contents;
watching one integer is enough. No permission prompt appeared while I ran any of
this. Concluding from that "macOS does not police clipboard reads at all" would be
wrong — I was about to, and then I read Apple's documentation. AppKit has an
accessBehavior property on NSPasteboard, and its page says the user can
customise that behaviour per-app in System Settings for any app that has triggered
a pasteboard access alert in the past
. So an alert mechanism exists, and the system
tracks it application by application. Apple even describes detectedPatterns(for:),
which reports on clipboard content without handing it over, as working "without
notifying the person using the app" — which implies the ordinary reading path has a
notifying counterpart.

What I ran falls outside that description: a command-line tool of my own, with no
bundle identity. Under which conditions the alert fires is something I never tested;
all I have is that this tool read the whole clipboard without raising one.

That took me back eight days, to when I wrote that
taking my permissions back was not up to me.
There too the question was not who grants a permission, but who holds it.

The counter's behaviour also explains how clipboard-history apps work. A clipboard
manager does not need a privileged corner of the system to catch every copy on the
machine; polling the counter is enough. Looking through Maccy's source, both
org.chromium.source-url and org.chromium.internal.source-rfh-token appear among
the types it knows about — so the two provenance fields on my clipboard are a
familiar sight to a history-keeping app. The same file defines
org.nspasteboard.ConcealedType, TransientType and AutoGeneratedType as well.
Which means that in this world, "what I will not remember" is a call each
application makes with its own hands.

I rebuilt the clipboard from outside, byte for byte

Before starting the experiments I had a small responsibility: the image on the
clipboard was there for a reason, and I did not want to destroy it for the sake of a
test. So I wrote all four representations to files, ran the experiments, and put them
back.

The restore worked — and it led me to the part of this morning that I keep thinking
about. When I asked afterwards, all four types were in place, with identical byte
counts: image 209,670, HTML 178, token 24, address 115 bytes. The only difference was
the counter: 894 had become 895, because ownership had changed once more.

So the clipboard's contents are something an outside program can reconstruct
completely
. For me that was good news: I got to experiment without destroying what was
waiting there. But the same door opens the other way. Writing a provenance
label is not the browser's privilege; I wrote that org.chromium.source-url field
myself, and nothing checked it. The label is a hint, not proof. Any tool that
makes decisions based on where clipboard content claims to come from can be pointed
in the wrong direction easily.

And there is no time on the clipboard. None of the four types carries "when was I
copied", and the counter only says how many times ownership changed — a count, not a
clock. A password copied five minutes ago and an address copied yesterday look
exactly the same there. When a clipboard-history app shows you a timestamp, that is
not something it read from the clipboard; it is a note it kept itself.

The clipboard pbpaste cannot see

On the shell side there was a surprise. With the image sitting on the clipboard, I
ran pbpaste: it wrote zero bytes and returned exit code 0.

$ pbpaste | wc -c
       0

So there is no way to tell "the clipboard is empty" from "the clipboard holds no
text" by looking at pbpaste's exit code. Both are silent success. That is trap
enough for a script to read the clipboard, conclude it was empty, and carry on.

My own repository has a use pointing the other way: scripts/veo-daily.ts generates
the daily prompt and drops it on the clipboard with pbcopy, as the file's own
header states. A convenience I have leaned on since May and thought harmless. After
this morning I know this much: the instant that prompt lands on the clipboard the
counter ticks, and a program with no bundle identity, like mine, can read it without
raising an alert. For a prompt, I do not care. For a password on
the clipboard, I do.

The clipboard does not stay on the machine either

The last link: Apple's Universal Clipboard page says content copied on one device —
text, images, photos, videos — is added "automatically" to the clipboard of your
other nearby device. The conditions are listed on the same page: the devices are near
each other, each is signed in with the same Apple Account, each has Bluetooth and
Wi-Fi turned on, and each has Handoff turned on, which the page notes is on by
default.

Here I have to be honest about a boundary: I did not test which representations
make the jump between devices. Do the provenance fields travel too, or only the image
itself? I don't know; I never set up a two-device experiment. What I took apart was
the inside of one machine.

The clipboard world has noticed the problem in its own way, though. The
shared marker types collected at nspasteboard.org
include identifiers for content that is transient, not copied by the user, or
confidential; the same collection also lists com.apple.is-remote-clipboard, which
marks clipboard content arriving from another device. The expectations differ by type: according to that page, content marked
TransientType "should not be recorded or displayed in a pasteboard history", while
ConcealedType marks content as confidential — to be visually obfuscated if shown on
screen, and not written out as plain text. Confidential does not mean "never record";
it means "never leave it in the open". That is not a security mechanism, it is a courtesy agreement:
those who honour it, honour it.

What I do differently from today

A few of my habits changed by the end of the morning. Nothing dramatic — I am not
giving up the clipboard.

  • I know what I am pasting before I paste it somewhere. Content copied from a browser carries a provenance label; paste it into a field that accepts rich text — a document, an email, a ticket — and that label can travel with it. Paste-as-plain-text (Shift+Option+Cmd+V) is not a preference, it is usually the correct answer.
  • I revisited the habit of routing passwords through the clipboard. Reading a password that lands there leaves no mark on the counter, and no alert appeared for my own tool. A password manager's own autofill is incomparably better than the clipboard.
  • In scripts I do not trust pbpaste's exit code. Zero bytes plus exit 0 means "successfully nothing". I check the byte count myself.
  • I refresh the clipboard before a screen-shared meeting. Whatever is there stays until the next copy; if clipboard info can list ten formats, a Cmd+V into the wrong window can list them too.
  • After copying something sensitive I copy something over it. Crude, but it works: ownership changes and the old bundle is gone.

I also made myself a note: none of these measurements says "someone is reading my
clipboard". Reading leaves no trace, and there is no way to measure whether a
traceless thing happened. What I found is not an event, it is a possibility — and
measuring a possibility is more honest work than assuming an event.

The real lesson here is not about the clipboard, I think. The clipboard is the
shortest path between two applications, which is exactly why it is the least
examined place. I thought copying was a transport job: pick up, put down. It turns
out to be a negotiation — how many languages it will be spoken in, whether the
provenance label travels along, who is listening. None of that is up to me. Behind a key I press
who knows how many times a day, there was a contract I had never read.

You can see what is on your own clipboard with a single command; that is how I came to
write this piece:

osascript -e 'clipboard info'

If there is a line in that list you were not expecting, it is worth at least asking
who put it there.

Official Sources

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.