Skip to content

Conversation

@sosukesuzuki
Copy link
Member

@sosukesuzuki sosukesuzuki commented Aug 19, 2025

What does this PR do?

Fixes namespace import objects inheriting from Object.prototype, preventing prototype pollution and ensuring ES specification compliance.

import * as mod from './mod.mjs'

Object.prototype.foo = function() {
    console.log('hello');
}

mod.foo(); // This should throw, but succeeded before

original report: https://x.com/sapphi_red/status/1957843865722863876

How did you verify your code works?

I added a test that verifies:

  • mod.maliciousFunction() throws when Object.prototype.maliciousFunction is added (prevents pollution)
  • __esModule property still works
  • Original exports remain accessible

@robobun
Copy link
Collaborator

robobun commented Aug 19, 2025

Updated 11:47 AM PT - Aug 19th, 2025

@autofix-ci[bot], your commit 60fa786 has 4 failures in Build #23371:


🧪   To try this PR locally:

bunx bun-pr 21984

That installs a local version of the PR into your bun-21984 executable, so you can run:

bun-21984 --bun

@sosukesuzuki sosukesuzuki changed the title Prevent Object.prototype pollution in imported namespace objects Prevent namespace objects from inheriting Object.prototype Aug 19, 2025
@Jarred-Sumner Jarred-Sumner marked this pull request as ready for review August 19, 2025 23:40
@Jarred-Sumner Jarred-Sumner merged commit decf84c into main Aug 19, 2025
59 of 60 checks passed
@Jarred-Sumner Jarred-Sumner deleted the dont-extend-object-proto branch August 19, 2025 23:40
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.

4 participants