# Sec-CH-Device-Memory header and navigator.deviceMemory

> Chrome builds the Sec-CH-Device-Memory header from the same function as navigator.deviceMemory, so a change on the script side alone sends the real figure.

Source: https://mosaicbrowser.com/blog/sec-ch-device-memory-header

## deviceMemory and Sec-CH-Device-Memory are one number read twice

Chrome builds the Sec-CH-Device-Memory header from the same function as navigator.deviceMemory, so a change on the script side alone sends the real figure.

![8 vs 32: The page said 8, the header said the real figure](https://mosaicbrowser.com/covers/sec-ch-device-memory-header.webp)

`navigator.deviceMemory` and the `Sec-CH-Device-Memory` request header carry the same number, and in Chromium they come from the same function. A page reads it in script; a server that asked for it with `Accept-CH` reads it in the header of every later request to its origin. If you change the script side and not the function, the two disagree, and the header gives the real figure to a server that never ran a line of JavaScript. We found exactly that in the open-source fingerprint code our engine started from.

## Where the Sec-CH-Device-Memory header gets its number

Both routes end at `ApproximatedDeviceMemory::GetApproximatedDeviceMemory()` in `third_party/blink/common/device_memory/`. The script route goes through the `deviceMemory` accessor on `Navigator`. The header route does not. `frame_fetch_context.cc`, the code that attaches client hints to outgoing requests, calls `GetApproximatedDeviceMemory()` directly when it builds `Sec-CH-Device-Memory` and the older `Device-Memory` header. It never touches the accessor.

The value itself is coarse on purpose. Chromium takes the machine's physical memory in gigabytes, rounds it to the nearest power of two, then clamps it to a range. In the Chromium source our engine is built from, that range is 2 to 32 on desktop and 1 to 8 on Android. So a 64 GB Mac reports 32, a 16 GB laptop reports 16, and a phone with 12 GB reports 8.

The header is not sent by default. A server has to ask, by answering a request with `Accept-CH: Sec-CH-Device-Memory`, and the origin has to be HTTPS or local. From the next request on, Chrome attaches it ([Accept-CH and Critical-CH](https://mosaicbrowser.com/blog/accept-ch-critical-ch) has how that opt-in works and how `Critical-CH` gets it onto the first page too).

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: Machines that exist](https://mosaicbrowser.com/features/real-fingerprints)

## The change that spoofed half of it

Tesseract Chrome, our engine, began as a port of an open-source set of fingerprint changes onto stock Chromium. Its memory change replaced the body of the `deviceMemory` accessor with a hard `return 8;`.

That had two faults, and either alone would have been enough to drop it.

The first is the second route. The accessor said 8; `GetApproximatedDeviceMemory()` was untouched, so the header still carried the host's own figure. On a 32 GB machine, a page's script read 8 and the same page's requests said 32, once the site had asked. A server comparing the two needs no JavaScript at all to see the header, and one line to read the script value.

The second is that 8 was the same for every profile. A spoof every profile shares adds nothing between profiles, and it can only disagree with the machine a profile claims to be. A profile drawn as a 32 GB workstation that reports 8 is wrong in the one direction a real desktop Chrome would only take on an 8 GB box.

We found the header route while building the engine, by doing what the fix now requires every time: searching the renderer for every caller of the value's source, not just the class a page would use. The habit came from the same batch of work, which found five values with a second route. The screen size had a CSS route through `matchMedia`, and the storage quota had a deprecated prefixed API.

## Claiming it at the source

`0128-device-memory-at-the-source` edits `approximated_device_memory.cc`, so the claim lives where both callers look. `0126` deletes upstream's `return 8;` and restores the one line stock Chromium has there, `return ApproximatedDeviceMemory::GetApproximatedDeviceMemory();`. The figure itself arrives on a `--fingerprint-*` switch at launch.

Rounding is copied from Chromium line for line. Clamping isn't, and for a dull reason: upstream chooses the range with `BUILDFLAG(IS_ANDROID)`, a compile-time test, and Tesseract is one desktop build that also wears Android profiles. Ours asks the profile instead. Android gets 1 to 8. Everything else gets 2 to 32.

We got that range wrong once ourselves. The first version of `0128` used the specification's old ladder, `0.25, 0.5, 1, 2, 4, 8`, capped at 8, with a comment saying a browser reporting 32 would be the only one on the web doing it. Our comparison against Google's own unbranded Chrome for Testing of the same major then read this on a 64 GB machine:

```
stock  navigator.deviceMemory  32
ours                            8

```

Chromium had moved the desktop clamp to 2 to 32. The cap we had written down was true when written and false by the time it was compared.

## Four descriptions of one number

The clamp change landed in the engine and in the generator. It did not land in the validator, or in `check:engine-live`, the script that launches the built browser and compares what it prints with what the profile says. Both of those still had the old ladder pasted in as a literal. Next build:

```
npm run check:exit             Could not generate a coherent fingerprint after 1 attempts
npm run check:devices          … after 12 attempts
npm run check:engine-live      ✗ deviceMemory (ladder): got 32, claimed 8

```

Twelve attempts is the generator's retry limit. It drew a 16 or 32 GB desktop, rounded it the new way, handed it to the validator, got told no, and tried again until it ran out. The fix was to stop writing the numbers down: `memoryClamp(os)` holds them, and the validator and live check import it from the compiled generator.

`compare-with-stock.mjs` changed too. It used to exempt `values.deviceMemory` by name. Now it fails the row in two cases: our value equals the stock browser's on the same Mac (the engine change did nothing), or our value isn't what the profile claimed (the arithmetic moved). Stock 32 beside ours 16 on a 16 GB claim passes. That is the same test that found the values every profile [inherited from this Mac](https://mosaicbrowser.com/blog/values-inherited-from-the-host): if a number matches the computer rather than the claim, it was never claimed. How the rest of a profile's hardware is drawn so the numbers agree with each other is on [real fingerprints](https://mosaicbrowser.com/features/real-fingerprints).

## Questions

### What is the Sec-CH-Device-Memory header?

A client hint carrying the device's approximate memory in gigabytes, rounded to a power of two. Chrome sends it on requests to a secure origin that has asked for it with Accept-CH, alongside the older Device-Memory header.

### Is Sec-CH-Device-Memory the same value as navigator.deviceMemory?

Yes. In Chromium both come from one function, ApproximatedDeviceMemory::GetApproximatedDeviceMemory(). The header is built in frame_fetch_context.cc by calling that function directly, without going through the JavaScript accessor.

### What values can navigator.deviceMemory return?

Powers of two, rounded from the real memory to the nearest step and then clamped. In the Chromium source our engine is built from, desktop is clamped to 2 to 32 and Android to 1 to 8.

### Why does my server not receive Sec-CH-Device-Memory?

Chrome sends it only after the origin opts in with an Accept-CH response header, and only over HTTPS or a local address. The first request to a site never carries it, because the opt-in arrives in the response.

## Related

[Accept-CH and Critical-CH: how a server asks for more](https://mosaicbrowser.com/blog/accept-ch-critical-ch): Accept-CH asks Chrome for more client hints on the next request; Critical-CH makes it retry the first. A server sees both requests and can compare them.

[Your dark mode is sent as a request header](https://mosaicbrowser.com/blog/sec-ch-prefers-headers): Sec-CH-Prefers-Color-Scheme sends your dark mode setting to any server that asks. On our profiles it carried this Mac's own settings, until each drew its own.

[The values every profile inherited from this Mac](https://mosaicbrowser.com/blog/values-inherited-from-the-host): A browser fingerprint value inherited from the host is identical across two unrelated profiles and equal to the computer. That test found dark mode and more.

[Machines that exist: fingerprints drawn from real hardware](https://mosaicbrowser.com/features/real-fingerprints): Mosaic draws each profile's GPU, screen, CPU, memory and fonts from one real device, so the parts of a fingerprint agree with each other and with the host.

[Browser fingerprint: what a site can read about your machine](https://mosaicbrowser.com/glossary/browser-fingerprint): A browser fingerprint is the set of values a site reads about your browser and computer, which together recognize you without cookies. What goes into one.







[How Chrome writes Accept-Language, q-values and all](https://mosaicbrowser.com/blog/how-chrome-writes-accept-language): Chrome writes Accept-Language from its language list: first tag bare, then q=0.9, 0.8 and down by 0.1 to a floor of 0.1. A hand-typed header rarely matches.

## Mosaic, on your own computer

The browser this blog is about: its own Chromium, fingerprints from real machines and a proxy IP per profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

Mosaic is a desktop app

Email yourself the link and open it on your computer.
