Skip to content

Commit

Permalink
fix: remove unintended exposure of private material via enumerables
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Mar 28, 2019
1 parent 988bbaf commit 946d9df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions lib/jwk/key/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class Key {

Object.defineProperties(this, {
[KEYOBJECT]: { value: isObject(keyObject) ? undefined : keyObject },
private: { value: keyObject.type === 'private', enumerable: keyObject.type === 'private' },
public: { value: keyObject.type === 'public', enumerable: keyObject.type === 'public' },
private: { value: keyObject.type === 'private' },
public: { value: keyObject.type === 'public' },
alg: { value: alg, enumerable: alg !== undefined },
use: { value: use, enumerable: use !== undefined },
kid: {
Expand Down Expand Up @@ -57,11 +57,8 @@ class Key {
members = this.constructor[PUBLIC_MEMBERS]
}

const result = Object.entries(this).reduce((acc, [prop, value]) => {
if (members.has(prop)) {
acc[prop] = value
}

const result = [...members].reduce((acc, key) => {
acc[key] = this[key]
return acc
}, { kty: this.kty, kid: this.kid })

Expand All @@ -87,14 +84,14 @@ class Key {
Object.entries(jwk)
.filter(([key]) => props.has(key))
.reduce((acc, [key, value]) => {
acc[key] = { value, enumerable: true, configurable: false }
acc[key] = { value, enumerable: this.constructor[PUBLIC_MEMBERS].has(key), configurable: false }
return acc
}, {})
)

return this[component]
},
enumerable: true,
enumerable: this.constructor[PUBLIC_MEMBERS].has(component),
configurable: true
}
return acc
Expand Down
2 changes: 1 addition & 1 deletion lib/jwk/key/oct.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class OctKey extends Key {
value: this[KEYOBJECT] ? this[KEYOBJECT].symmetricKeySize * 8 : undefined
},
k: {
enumerable: true,
enumerable: false,
get () {
if (this[KEYOBJECT]) {
Object.defineProperty(this, 'k', {
Expand Down

0 comments on commit 946d9df

Please sign in to comment.