GithubHelp home page GithubHelp logo

uid-safe's Introduction

uid-safe

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

URL and cookie safe UIDs

Create cryptographically secure UIDs safe for both cookie and URL usage. This is in contrast to modules such as uid2 whose UIDs are actually skewed due to the use of % and unnecessarily truncate the UID. Use this if you could still use UIDs with - and _ in them.

Installation

$ npm install uid-safe

API

var uid = require('uid-safe')

uid(byteLength, callback)

Asynchronously create a UID with a specific byte length. Because base64 encoding is used underneath, this is not the string length. For example, to create a UID of length 24, you want a byte length of 18.

uid(18, function (err, string) {
  if (err) throw err
  // do something with the string
})

uid(byteLength)

Asynchronously create a UID with a specific byte length and return a Promise.

Note: To use promises in Node.js prior to 0.12, promises must be "polyfilled" using global.Promise = require('bluebird').

uid(18).then(function (string) {
  // do something with the string
})

uid.sync(byteLength)

A synchronous version of above.

var string = uid.sync(18)

License

MIT

uid-safe's People

Contributors

caub avatar dougwilson avatar jonathanong avatar magnitus- avatar sehrope avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uid-safe's Issues

Doc Improvement

In the doc:

"To use promises, you must define a global Promise if necessary."

Maybe it's obvious for readers already familiar with Promises (especially in the context of a Node.js environment), but for those new to it, a tad more details would be helpful.

The way it is phrased right now, it makes it seem as if you are expected to implement this yourself.

Something like this might be more helpful:

"To use promises, a global Promise variable must be defined in your environment. This is not the case for current versions of Node.js, but it can be achieved with a polyfill like the one in the es6-promise project."

mz really needed?

Hi,

is it really needed require 'mz/crypto' ??

I mean, could module be rewritten doing the same job without install extra 600KB dependencies ?

Please update reference to repository

Hello,

In package.json I see:

"repository": "jonathanong/uid-safe",

But the real project homepage seems to be "crypto-utils/uid-safe/"

Can you please consider to update it ?

UID-Safe potentially vulnerable to a predictable state

summary

Potentially vulnerable to an attack where entropy is exhausted and the library falls back to predictable random byte generation.

Code should warn the operator when entropy is exhausted to detect attack.

issue

The code tries crypto.randomBytes and silently falls back to crypto.pseudoRandomBytes which can happen if entropy is exhausted.

function randomBytes(length, callback) {
  crypto.randomBytes(length, function (err, buf) {
    if (!err) return callback(null, buf)
    crypto.pseudoRandomBytes(length, function (err, buf) {
      if (err) return callback(err)
      callback(null, buf)
    })
  })
}

Notes from crypto documentation:

NOTE: Will throw error or invoke callback with error, if there is not enough accumulated entropy to generate cryptographically strong data. In other words, crypto.randomBytes without callback will not block even if all entropy sources are drained.

[crypto.pseudoRandomBytes] Generates non-cryptographically strong pseudo-random data. The data returned will be unique if it is sufficiently long, but is not necessarily unpredictable. For this reason, the output of this function should never be used where unpredictability is important, such as in the generation of encryption keys.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.