npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongoose-advanced-encryption

v0.10.4

Published

Mongoose plugin for document fields encryption and authentication.

Downloads

10

Readme

mongoose-advanced-encryption

Mongoose plugin for document fields encryption and authentication preserving ability to query for encrypted field.

Overview

This plugin provides encryption, hashing (blind indexing) and authentication for Mongoose document fields. Fields encryption is performed using AES-256-CBC algorithm, hashing as well as authentication using HMAC-SHA-512.

Requirements

Defining field encryption settings

The plugin works on per-field encryption basis. To mark field to be encrypted it is necessary to specify it's encryption options using encrypt option on it's SchemaType definition. The encrypt option can be either a boolean (e.g. true will enable encryption of the field, false is the same as not setting the option at all) or an Object with field's encryption settings, which would override defaults. It is possible to specify default encrypt options on schema level as encrypt field on plugin options. If it's not specified plugin's hard-coded config will be used.

Getting Started

npm install mongoose-advanced-encryption --save

Generate encryption keys:

openssl rand -base64 32; openssl rand -base64 64; openssl rand -base64 64;

Plugin Options

  • encryptionKey - a 32-byte base64 string.
  • hashingKey - a 64-byte base64 string.
  • authenticationKey - a 64-byte base64 string.
  • decryptAfterSave - Enables automatic documents decryption passed to doc.save() callback.
  • skipAuthenticationIfNoSignature - Disables document authentication if document has no signature.
  • encrypt - Allows to adjust plugin's default field encryption options on per schema level. These options can be overridden on per field level.
    • hash - Indicates either hash should be created or not.
      • index - Indicates either index for the hash field should be created of not.
Default plugin configuration is the following:
const defaultConfig = {
    decryptAfterSave: false,
    encrypt: {
        hash: { // means that hash will be created, but without MongoDB index
            index: false
        }
    }
}

Instance Methods

  • encEncrypt
  • encDecrypt
  • encSign
  • encAuthenticate

Supported query methods

With the methods below encryption/decryption works transparently.

  • count
  • countDocuments
  • find
  • findOne
  • findOneAndRemove
  • findOneAndUpdate
  • update

Security Issue Reporting / Disclaimer

I am in no way a security expert. The plugin is a result of deep research on security-related topics, but I do not have any underlying expertise in security. If you wish to use this plugin in your project please analyse the code carefully and use it at your own risk. If you find any security-related issues, please email me at [email protected]. For non-security-related issues, feel free to open a Github issue or pull request.

Credits

Big thanks to mongoose-encryption plugin authors for the source of inspiration. The mongoose-encryption plugin is great, but since authors decided to keep it simple for security reasons it is not sufficient enough for our use case. That is why a decision to write a more "advanced" plugin was made.

Also another big thanks goes to this article author.

License

The MIT License (MIT)

Copyright (c) 2018 Vladyslav Mashkin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.