Skip to content

fix: text matching Object.prototype property names rendered as image#768

Open
rafaumeu wants to merge 1 commit into
vercel:mainfrom
rafaumeu:fix/prototype-pollution-text-746
Open

fix: text matching Object.prototype property names rendered as image#768
rafaumeu wants to merge 1 commit into
vercel:mainfrom
rafaumeu:fix/prototype-pollution-text-746

Conversation

@rafaumeu

Copy link
Copy Markdown

Problem (#746)

When text content passed to Satori exactly matched an Object.prototype property name (e.g. "constructor", "toString", "valueOf"), the text was silently not rendered. Instead, an <image> element with an invalid href was emitted.

Root Cause

Two locations in src/text/index.ts used bracket-notation lookup on a user-provided graphemeImages object:

  1. isImage(s) (line 122): graphemeImages[s] — when s is "constructor", this returns Object.prototype.constructor (a truthy function), so the text was incorrectly treated as an image.

  2. Rendering path (line 558): graphemeImages[text] — same issue, returns the inherited property instead of undefined.

Fix

Use Object.prototype.hasOwnProperty.call() to check for own properties before accessing the value:

// Before
graphemeImages[s]

// After
Object.prototype.hasOwnProperty.call(graphemeImages, s) && graphemeImages[s]

Testing

All 433 existing tests pass. The fix only affects edge cases where text exactly matches Object.prototype property names — normal usage is unaffected.

…ercel#746)

When text content exactly matched an Object.prototype property name
(e.g. 'constructor', 'toString', 'valueOf'), the bracket-notation lookup
graphemeImages[s] returned the inherited property instead of undefined,
causing the text to be treated as an image reference.

Fix: use Object.prototype.hasOwnProperty.call() before accessing the value
in both isImage() and the rendering path.
@rafaumeu rafaumeu requested a review from shuding as a code owner June 17, 2026 21:45
@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
satori-playground Ready Ready Preview, Comment, Open in v0 Jun 17, 2026 9:46pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant