New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-field-encryption

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-field-encryption - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

28

lib/mongoose-field-encryption.js

@@ -24,4 +24,11 @@ 'use strict';

if (!options || !options.secret) {
throw new Error('missing required secret');
}
const fieldsToEncrypt = options.fields || [];
const secret = options.secret;
// add marker fields to schema
for (let field of options.fields) {
for (let field of fieldsToEncrypt) {
let encryptedFieldName = encryptedFieldNamePrefix + field;

@@ -63,3 +70,3 @@ let schemaField = {};

try {
decryptFields(data, options.fields, options.secret);
decryptFields(data, fieldsToEncrypt, secret);
next();

@@ -73,3 +80,3 @@ } catch (err) {

try {
encryptFields(this, options.fields, options.secret);
encryptFields(this, fieldsToEncrypt, secret);
next();

@@ -83,3 +90,3 @@ } catch (err) {

for (let field of options.fields) {
for (let field of fieldsToEncrypt) {

@@ -93,3 +100,3 @@ let encryptedFieldName = encryptedFieldNamePrefix + field;

let updateObj = { $set: {} };
updateObj.$set[field] = encrypt(plainTextValue, options.secret);
updateObj.$set[field] = encrypt(plainTextValue, secret);
updateObj.$set[encryptedFieldName] = true;

@@ -106,8 +113,15 @@ this.update({}, updateObj);

schema.methods.stripEncryptionFieldMarkers = function() {
for (let field of fieldsToEncrypt) {
let encryptedFieldName = encryptedFieldNamePrefix + field;
this.set(encryptedFieldName, undefined);
}
};
schema.methods.decryptFieldsSync = function() {
decryptFields(this, options.fields, options.secret);
decryptFields(this, fieldsToEncrypt, secret);
};
schema.methods.encryptFieldsSync = function() {
encryptFields(this, options.fields, options.secret);
encryptFields(this, fieldsToEncrypt, secret);
};

@@ -114,0 +128,0 @@

{
"name": "mongoose-field-encryption",
"version": "0.0.4",
"version": "0.0.5",
"description": "A simple symmetric encryption plugin for fields with string values.",

@@ -10,3 +10,5 @@ "main": "lib/mongoose-field-encryption.js",

"scripts": {
"test": "mocha"
"test": "mocha",
"coverage": "URI='mongodb://mfe:mfe@localhost/mongoose-field-encryption-test' istanbul cover ./node_modules/mocha/bin/_mocha",
"coverage-report": "URI='mongodb://mfe:mfe@localhost/mongoose-field-encryption-test' istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},

@@ -45,4 +47,7 @@ "repository": {

"chai": "^3.5.0",
"mocha": "^3.1.0"
"coveralls": "^2.11.14",
"istanbul": "^0.4.5",
"mocha": "^3.1.0",
"mocha-lcov-reporter": "^1.2.0"
}
}
# mongoose-field-encryption
[![Build Status](https://travis-ci.org/victorparmar/mongoose-field-encryption.svg?branch=master)](https://travis-ci.org/victorparmar/mongoose-field-encryption)
[![Build Status](https://travis-ci.org/victorparmar/mongoose-field-encryption.svg?branch=master)](https://travis-ci.org/victorparmar/mongoose-field-encryption) [![Coverage Status](https://coveralls.io/repos/github/victorparmar/mongoose-field-encryption/badge.svg?branch=master)](https://coveralls.io/github/victorparmar/mongoose-field-encryption?branch=master)

@@ -69,2 +69,3 @@ A simple symmetric encryption plugin for individual fields. The goal of this plugin is to encrypt data but still allow searching over the fields. This plugin relies on the Node `crypto` module. Encryption and decryption happen transparently during save and find.

- `decryptFieldsSync()`: synchronous call that decrypts encrypted fields as given by the plugin options
- `stripEncryptionFieldMarkers()`: synchronous call that removes the encryption field markers (useful for returning documents without letting the user know that something was encrypted)

@@ -71,0 +72,0 @@ Multiple calls to the above methods have no effect, i.e. once a field is encrypted and the `__enc_` marker field value is set to true then the ecrypt operation is ignored. Same for the decrypt operation.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc