Skip to content

Commit

Permalink
fix: address prototype pollution
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Jan 4, 2021
1 parent 77f684e commit 90401ee
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### 3.2.2 (2021-01-04)


### Bug Fixes

* address prototype pollution issue ([#108](https://www.github.com/yargs/y18n/issues/108)) ([a9ac604](https://www.github.com/yargs/y18n/commit/a9ac604abf756dec9687be3843e2c93bfe581f25))
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function Y18N (opts) {
this.fallbackToLanguage = typeof opts.fallbackToLanguage === 'boolean' ? opts.fallbackToLanguage : true

// internal stuff.
this.cache = {}
this.cache = Object.create(null)
this.writeQueue = []
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "y18n",
"version": "3.2.1",
"version": "3.2.2",
"description": "the bare-bones internationalization library used by yargs",
"main": "index.js",
"scripts": {
Expand Down
18 changes: 18 additions & 0 deletions test/y18n-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ describe('y18n', function () {
})
})

// See: https://github.com/yargs/y18n/issues/96,
// https://github.com/yargs/y18n/pull/107
describe('prototype pollution', function () {
it('does not pollute prototype, with __proto__ locale', function () {
const y = y18n()
y.setLocale('__proto__')
y.updateLocale({ polluted: '👽' })
y.__('polluted').should.equal('👽')
;(typeof polluted).should.equal('undefined')
})

it('does not pollute prototype, when __ is used with __proto__ locale', function () {
const __ = y18n({ locale: '__proto__' }).__
__('hello')
;(typeof {}.hello).should.equal('undefined')
})
})

after(function () {
rimraf.sync('./test/locales/fr.json')
})
Expand Down

0 comments on commit 90401ee

Please sign in to comment.