Skip to content

fix(localize): build runtime translations map with a null prototype#69705

Open
arshsmith1 wants to merge 1 commit into
angular:mainfrom
arshsmith1:localize-translations-null-proto
Open

fix(localize): build runtime translations map with a null prototype#69705
arshsmith1 wants to merge 1 commit into
angular:mainfrom
arshsmith1:localize-translations-null-proto

Conversation

@arshsmith1

Copy link
Copy Markdown
Contributor

PR Checklist

PR Type

  • Bugfix

What is the current behavior?

Issue Number: N/A

loadTranslations builds the shared global $localize.TRANSLATIONS as a plain {} and then indexes it with message ids taken verbatim from the translations map, which is commonly parsed from a translation file. A translation whose id is __proto__ therefore assigns a ParsedTranslation through the inherited __proto__ setter, which reparents the map instead of storing the entry: the __proto__ translation is silently dropped, a later lookup for an id such as text resolves to the injected value through the prototype, and under node --disable-proto=throw the assignment throws.

What is the new behavior?

The translations store is created with Object.create(null) in both loadTranslations and clearTranslations, so a __proto__ message id is treated as an ordinary key. This mirrors the null-prototype hardening already used for outlet maps in the router url parser. Added a regression test that loads a __proto__ id alongside a normal one and checks the map is not reparented and the normal translation still resolves.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

loadTranslations stores parsed translations into the shared global
$localize.TRANSLATIONS keyed by message id. Those ids come verbatim from
the translations map (typically parsed from a translation file), so a
translation whose id is __proto__ assigns through the inherited __proto__
setter, reparenting the map rather than storing the entry (and throwing
under --disable-proto=throw). Create the map with Object.create(null) in
loadTranslations and clearTranslations so __proto__ is an ordinary key.
@pullapprove pullapprove Bot requested a review from atscott July 9, 2026 07:11
@angular-robot angular-robot Bot added the area: i18n Issues related to localization and internationalization label Jul 9, 2026
@ngbot ngbot Bot added this to the Backlog milestone Jul 9, 2026
@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: i18n Issues related to localization and internationalization target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants