Skip to content

Commit be21813

Browse files
committed
Tweak README
1 parent f484808 commit be21813

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

README.md

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@ Encrypted model attributes in your favourite ORM.
88

99
# Security model
1010

11-
* AES-256-GCM
12-
* 96-bit random nonce
13-
* 128-bit authentication tag
11+
* AES-256-GCM:
12+
* 96-bit random nonce
13+
* 128-bit authentication tag
1414
* Additional authenticated data:
15-
* Key id, allowing use of different keys for different attributes, or
16-
rotating keys over time without re-encrypting all data
17-
* [*Optional*] Object id, allowing to detect substitutions of encrypted
18-
values
15+
* Key id: use different keys for different attributes (or different users),
16+
rotate keys over time without re-encrypting all data
17+
* Object id: prevent substitution of encrypted values
1918

2019
All keys should be 32 bytes long, and cryptographically random. Manage these
2120
keys as you would any other credentials (environment config, keychain, vault).
22-
23-
Best way to generate keys:
21+
Generate keys with:
2422
```
2523
node -p "require('crypto').randomBytes(32).toString('base64')"
2624
```
@@ -37,9 +35,9 @@ specific scenarios:
3735
* Query injection via unsanitized input
3836

3937
Specifically, this does *not* provide any protection in cases of a compromised
40-
web app host, app-level vulnerabilities, or accidental leaks into persistent
41-
logs. It is also in no way a substitute for actually encrypting your backups,
42-
sanitizing all you input, et cetera.
38+
app host, app-level vulnerabilities, or accidentally leaking sensitive data
39+
into logs. It is also not a substitute for actually encrypting your backups,
40+
sanitizing your input, et cetera.
4341

4442
# Install
4543

@@ -50,13 +48,12 @@ npm install node-encrypted-attr
5048
# Use
5149

5250
While this module can be used stand-alone to encrypt individual values (see
53-
[tests](/test/)), it is designed to be wrapped in a plugin or hook for your
54-
favourite ORM. Eventually, this package may include such plugins for common
55-
ORMs, but for now, here's an example of integrating with [thinky](https://github.com/neumino/thinky):
56-
57-
## Thinky
51+
[tests](/test/encrypted-attr.spec.js)), it is designed to be wrapped into a
52+
plugin or hook for your favourite ORM. Eventually, this package may include
53+
such plugins for common ORMs, but for now, here's an example of integrating
54+
with [thinky](https://github.com/neumino/thinky):
5855

59-
```
56+
```js
6057
const EncryptedAttributes = require('node-encrypted-attr')
6158
const thinky = require('thinky')()
6259
const _ = require('lodash')
@@ -67,23 +64,24 @@ Model.encryptedAttributes = EncryptedAttributes(['secret'], {
6764
keys: {
6865
k1: 'bocZRaBnmtHb2pXGTGixiQb9W2MmOtRBpbJn3ADX0cU='
6966
},
70-
keyId: 'k1'
67+
keyId: 'k1',
68+
verifyId: true
7169
})
7270

73-
// Pre-save hook: encrypt any model attributes that need to be encrypted.
71+
// Pre-save hook: encrypt model attributes that need to be encrypted.
7472
Model.pre('save', function (next) {
7573
try {
76-
this.encryptedAttributes.encryptAll(obj)
74+
this.encryptedAttributes.encryptAll(this)
7775
process.nextTick(next)
7876
} catch (err) {
7977
process.nextTick(next, err)
8078
}
8179
})
8280

83-
// Post-save hook: decrypt any model attributes that need to be decrypted.
81+
// Post-save hook: decrypt model attributes that need to be decrypted.
8482
Model.post('save', function (next) {
8583
try {
86-
this.encryptedAttributes.decryptAll(obj)
84+
this.encryptedAttributes.decryptAll(this)
8785
process.nextTick(next)
8886
} catch (err) {
8987
process.nextTick(next, err)
@@ -93,17 +91,17 @@ Model.post('save', function (next) {
9391
// Post-retrieve hook: ditto.
9492
Model.post('retrieve', function (next) {
9593
try {
96-
this.encryptedAttributes.decryptAll(obj)
94+
this.encryptedAttributes.decryptAll(this)
9795
process.nextTick(next)
9896
} catch (err) {
9997
process.nextTick(next, err)
10098
}
10199
})
102100

103-
// Optionally, add some helper methods in case you need to set or read a value
104-
// directly, without going through model parser.
101+
// Optionally, add some helpers in case we need to set or read the value
102+
// directly (such as an update query), without going through model hooks.
105103
for (let attr of Model.encryptedAttributes.attributes) {
106-
Mode.define(_.camelCase(`encrypted ${attr}`), function (val) {
104+
Model.define(_.camelCase(`encrypted ${attr}`), function (val) {
107105
return Model.encryptedAttributes.encryptAttribute(this, val)
108106
}
109107
}

0 commit comments

Comments
 (0)