Giter Site home page Giter Site logo

cabinjs / bson-objectid Goto Github PK

View Code? Open in Web Editor NEW
202.0 202.0 33.0 99 KB

Construct ObjectIDs without the mongodb driver or bson module. Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.

License: Apache License 2.0

JavaScript 75.01% TypeScript 24.99%

bson-objectid's People

Contributors

abdelrahmanhafez avatar aeonrush avatar allouis avatar benatkin avatar hasezoey avatar karn09 avatar linusu avatar mremanuel avatar mwynholds avatar niftylettuce avatar rahatarmanahmed avatar rparet avatar ruzicic avatar titanism avatar ulrichb avatar viktor-ku avatar wendellmva avatar williamkapke 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

bson-objectid's Issues

Provide a way to set MACHINE_ID

I'm working on cordova based application and want to generate ObjectId in browser. From source code I see that MACHINE_ID is a random number and it means that I potentially may have issues when 2 clients of my application generate the same ObjectId.

In order to overcome this issue I could use cordova-plugin-device, retrieve uuid and use it as MACHINE_ID. That way I will make sure that all my clients generate unique ObjectIds.

Alternatevely it's possible to use userId as MACHINE_ID which is provided by my API.

I can create a PR if you are ok with suggestion:

import ObjectId from 'bson-objectid'

ObjectId.setMachineId(device.uuid)

Typescript import issue

Hi there,
keep getting
Value of type 'typeof ObjectID' is not callable error with Typescript

snippet

import ObjectID from 'bson-objectid';

const value = 'object-id-string';
const id = ObjectID(value);

package.json

"typescript": "~4.0.5"
    "bson-objectid": "^1.3.1",

Ignoring ts lint check will do the trick but still kind'a strange.
Anyone had some problems with that?

Cannot use namespace 'Buffer' as a type.

Using Vue with Typescript...

Running production build throws this error:

ERROR in C:/GIT/iAM/BridgeCareApp/VuejsApp/node_modules/bson-objectid/objectid.d.ts
21:25 Cannot use namespace 'Buffer' as a type.
19 | constructor(idString: string);
20 | constructor(array: number[]);

21 | constructor(buffer: Buffer);
| ^
22 |
23 | readonly id: string;
24 | readonly str: string;

Type for ObjectID does not match mongodb ObjectId

If you are using a typescript project and are trying to use the bson-objectid imported ObjectId it is missing 4 properties.

TS2739: Type 'ObjectID' is missing the following properties from type 'ObjectId': _bsontype, generationTime, toJSON,

Listed for convenience:

_bsontype
generationTime
toJSON
inspect

mongodb

I was wondering if this library exactly replicated how mongodb generates their random objectids?

Publishing `.idea` folder to npm

The .idea folder (webstorm generated I think) is been pushed to npm, please put it in the gitignore.
Great package btw.

$ ls -a
.  ..  .editorconfig  .idea  LICENSE  .npmignore  objectid.d.ts  objectid.js  package.json  README.md  test  typing-tests

Uncaught ReferenceError: _Buffer is not defined

Description
_Buffer is not defined in Node.js. If the program reaches this statement, an error will be thrown and, if uncaught, will crash the node process.

Minimal Reproduction
In Node.js REPL (tested against v16.13.2):

> _Buffer
Uncaught ReferenceError: _Buffer is not defined

Workaround
For Node.js, alias the Buffer global as _Buffer in your program entrypoint so that it is defined before calling anything in bson-objectid:

global['_Buffer'] = Buffer;

Possible Fix
Attempt to use _Buffer, else fall back to using Buffer. Just using normal Buffer global fixes things for Node.js so a global alias is not required.

ObjectID sometimes generates 26 characters

Using bson-objectid with browserify, occasionally ObjectID.generate() generates a 26 character id (and new ObjectID.toString() returns a blank string).

I suspect it happens because the pid for browsers is set to a random number between 0 and 100000. It seems to happen when the generated pid is > 0xFFFF (ex: once when this occurred, pid was set to 81783)

pid is NaN when used with browserify

I'm using this module with browserify and ObjectId.generate() is returning strings like 565c8e5032d34b0NaNa0ad07. Found that this is because when this line executes on the browser, process exists but process.pid does not.

A workaround is to use new ObjectId().toString(), which generates a correct id.

Typescript errors

Hi,

I pulled the npm package (version 1.2.3) into an Angular 5 project, using typescript. When I try to build the project I get two errors:

ERROR in node_modules/bson-objectid/objectid.d.ts(20,25): error TS2304: Cannot find name 'Buffer'.

src/app/term.service.ts(7,10): error TS2305: Module '"<path>/node_modules/bson-objectid/objectid"' has no exported member 'ObjectID'.

Does anyone know why this might happen and how to solve that problem?

IsValid returns true for invalid binary data

> ObjectId.isValid("�½��ļ���.zip")
true
> ObjectId("�½��ļ���.zip")
ObjectID(undefinedbdundefinedundefinedundefinedundefinedundefinedundefined2e7a6970)

Cannot get version 1.2.4 from npm

No matching version found for bson-objectid 1.2.4

I was hopping this could fix the issue with typescript and buffer reference.

Thanks

A vulnerability in ObjectID()

We found that ObjectID() allows an attacker to generate a malformed objectid by inserting an additional property to his user-input.

The vulnerable code is as follows: bson-objectid will return early if it detects _bsontype == ObjectID in user-input object. As a result, objects in arbitrary forms can bypass formatting if they have a valid bsontype.

https://github.com/williamkapke/bson-objectid/blob/eaaf20d828974c1a2b8e07b522b1ebdc86672f41/objectid.js#L29-L32

Unlike bson-objectid, the official implementation (shown in the following code) enforces a stricter early return condition, i.e., only if the constructor of the user-input object is ObjectID.
https://github.com/mongodb/js-bson/blob/cea186763527e4d3749a8234d335e9c395effe5b/lib/objectid.js#L59-L61

Reproduce script

var ObjectID = require("bson-objectid");

var json = {
    "mal_formkey": {
        "payload": "xxxx"
    },
    "_bsontype" : "ObjectID"
};

console.log(ObjectID(json));
console.log(ObjectID.isValid(ObjectID(json)));

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.