Giter Site home page Giter Site logo

Comments (12)

fta2012 avatar fta2012 commented on June 27, 2024 3

The older PRNG is easier but the new one is similarly vulnerable. You need to switch to crypto.getRandomValues if you really want it to be unpredictable.

from cuid.

ericelliott avatar ericelliott commented on June 27, 2024 3

This should be fixed now.

from cuid.

seangenabe avatar seangenabe commented on June 27, 2024 1

FYI crypto is already available in most browsers.

from cuid.

nealoke avatar nealoke commented on June 27, 2024

@fta2012 just out of interest, if you can't know the timestamp portion can you ever crack the whole thing?

from cuid.

fta2012 avatar fta2012 commented on June 27, 2024

You just need to search upwards from the last known timestamp. Also if it's a batch insert the next id is likely to be within the same millisecond as the others.

from cuid.

ericelliott avatar ericelliott commented on June 27, 2024

I'm open to a PR, with a caveat. For such an attack to work:

  1. You'd need to be running an old/buggy PRNG
  2. The thing you're searching for would need to be generated by the same client, during the same runtime instance as the known IDs. You'd also need to be able to search the ID space to land on the right millisecond.

Some older apps may be vulnerable to an ID guessing attack.

from cuid.

ericelliott avatar ericelliott commented on June 27, 2024

Agreed. Open to a PR.

from cuid.

fta2012 avatar fta2012 commented on June 27, 2024

If it's just replacing Math.random with the crypto version it should be a small change. I probably won't get to it so this is up for grabs for anyone who wants to contribute.

from cuid.

ericelliott avatar ericelliott commented on June 27, 2024

The crypto API is not in the browser.

from cuid.

MarkHerhold avatar MarkHerhold commented on June 27, 2024

I don't think that cuids being predictable is necessarily a bad thing.

from cuid.

ericelliott avatar ericelliott commented on June 27, 2024

@MarkHerhold For some apps, it could be a security risk.

from cuid.

ericelliott avatar ericelliott commented on June 27, 2024

I'm open to a PR that uses the crypto API if it's available. Note that it is available in IE11 with the ms prefix, so fallback to that if you can.

In Node, we'll have to use the Node crypto API to avoid this vulnerability... note that it is NOT compatible with universal JS, so we'll have to continue to use different builds for Node and Browsers. We could write a facade around the different APIs using a getRandomValues() function and import a different implementation depending on the build.

from cuid.

Related Issues (20)

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.