# GHSA-92M5-76FP-R4X7: Summary When ag-psd decodes enumerated values from Photoshop descriptors, it looks the file-supplied value up in a plain object without checking that the key is an own property

- Database: GitHub
- Severity: CVSS 4.8 (Medium)
- Published: 2026-11-16
- Modified: 2026-11-16

## Affected versions

- ag-psd (npm): through 34.2.0

## Description

### Summary

When ag-psd decodes enumerated values from Photoshop descriptors, it looks the file-supplied value up in a plain object without checking that the key is an own property. If a crafted PSD supplies an enum value that is the name of an inherited property, such as `__proto__`, `constructor`, `toString` or `hasOwnProperty`, the parser returns `Object.prototype` or a native function where it should return one of the documented string values.

ag-psd does not modify the returned object itself. But any application that later writes to that field, for example while normalising or annotating parsed data in place, writes to `Object.prototype`. That pollutes the prototype of every object in the process.

### Details

`createEnum` in `src/helpers.ts`:

```ts
export function createEnum<T extends string>(prefix: string, def: T, map: { [K in T]: string; }) {
	const rev = revMap(map);           // plain object: {} with reversed keys

	const decode = (val: string): T => {
		const value = val.split('.')[1];  // attacker-controlled, arbitrary length
		if (value && !rev[value]) {       // rev['__proto__'] is truthy -> check skipped
			if (Object.prototype.hasOwnProperty.call(map, value)) return value as any;
			const spaced = value.replace(/([A-Z])/g, ' $1').toLowerCase();
			if (Object.prototype.hasOwnProperty.call(map, spaced)) return spaced as any;
			throw new Error(`Unrecognized value for enum: '${val}'`);
		}
		return (rev[value] as any) || def; // returns inherited property
	};
	...
}
```

`rev` is created by `revMap()` as an ordinary object literal, so it inherits from `Object.prototype`. Descriptor enum values are read with `readAsciiStringOrClassId`, which accepts strings of any length. That means values like `__proto__` and `constructor` (unlike 4-character OSType keys) can be encoded in a file.

The fallback branch in the same function already uses `Object.prototype.hasOwnProperty.call`, and the engine data parsers (`setProperty` in `engineData.ts`, `getKey` in `engineData2.ts`) already guard against inherited keys. The main lookup in `decode` is the remaining gap.

`createEnum` is used to decode many fields, including blend modes, layer effect settings, text settings, slices, print settings and animation frame disposal. All of them can be reached from an untrusted PSD.

### Proof of concept

A minimal 1×1 RGB PSD with one image resource, **Print Information (ID 1082)**, holding a version-16 descriptor with a single enum item:

| Item key | Type   | Enum type | Enum value  |
|----------|--------|-----------|-------------|
| `Inte`   | `enum` | `Inte`    | `__proto__` |

Parsing it:

```js
const { readPsd } = require('ag-psd');
const psd = readPsd(buffer, { useImageData: true });

const ri = psd.imageResources.printInformation.renderingIntent;
console.log(ri === Object.prototype); // true
```

Results observed for other values:

| Enum value       | `renderingIntent` returned            |
|------------------|---------------------------------------|
| `__proto__`      | `Object.prototype`                    |
| `constructor`    | `function Object() { [native code] }` |
| `toString`       | `function toString() { [native code] }` |
| `hasOwnProperty` | `function hasOwnProperty() { [native code] }` |

The documented type is a string union (`'perceptual' | 'saturation' | 'relative colorimetric' | 'absolute colorimetric'`).

Example of an application-side write leading to global pollution:

```js
const info = psd.imageResources.printInformation;
if (typeof info.renderingIntent === 'object') info.renderingIntent.flag = true;
console.log(({}).flag); // true, Object.prototype has been modified
```


### Impact

- **Type confusion (always):** applications that rely on the TypeScript types and treat enum fields as strings may crash or behave unexpectedly, for example `layer.effects.dropShadow[0].blendMode.toUpperCase()` throwing, or switch/lookup logic taking unintended branches.
- **Prototype pollution (conditional):** if the consuming application, or a framework it passes parsed data to, writes properties onto a decoded enum value, those writes land on `Object.prototype`. Depending on the application, that can lead to logic bypasses, denial of service or worse. This needs the consuming application to perform such a write; **ag-psd does not modify `Object.prototype` on its own.**
- **Write path:** a document containing such a value throws when written back with `writePsd`, because `encode` does not recognise it. A read → modify → write pipeline can therefore be made to fail on demand.

Applications that parse PSD, PSB or ABR files from untrusted sources (file upload handlers, conversion services, browser-based editors) are exposed to the type confusion in every case.

## References

- https://github.com/Agamnentzar/ag-psd/security/advisories/GHSA-92m5-76fp-r4x7

Page: https://cve.now/GHSA-92M5-76FP-R4X7

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