Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize generation of objectId for a custom class? #4363

Closed
vshy108 opened this issue Nov 20, 2017 · 13 comments
Closed

Customize generation of objectId for a custom class? #4363

vshy108 opened this issue Nov 20, 2017 · 13 comments
Assignees
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@vshy108
Copy link

vshy108 commented Nov 20, 2017

Is it possible to modify the way to generate objectId for custom class instead of the auto generate 10 pseudo random 10 character string? Is it possible to have more than 10 characters objectId? thanks

@flovilmart
Copy link
Contributor

What would be your use case?

@milesrichardson
Copy link

milesrichardson commented Nov 30, 2017

I also wanted to increase the length of objectIds. My use case is simply to make brute forcing attempts more difficult.

There is an undocumented config option objectIdSize which is set to 10 by default. The only hard coded reference I could find to objectId being 10 is in SchemaController L140: const userIdRegex = /^[a-zA-Z0-9]{10}$/;

I haven't set CLP yet but it looks like this would cause problems with setting CLP to a userID.

@flovilmart Could you comment on why the config option is undocumented, and what side effects we should expect from changing the objectId size? Maybe that userIdRegex should be changed to reference the config value instead of hard coding 10?

EDIT: I just quickly tested setting CLP in the dashboard by entering a 40 character userId (after setting objectIdSize = 40), and I did not receive the error "not a valid key for class level permissions" I would have expected.

@flovilmart
Copy link
Contributor

That’s an omission, and should be fixed in a subsequent PR.

@flovilmart flovilmart added the type:bug Impaired feature or lacking behavior that is likely assumed label Nov 30, 2017
@flovilmart flovilmart self-assigned this Nov 30, 2017
@milesrichardson
Copy link

Thanks. But could you please clarify what exactly is the omission? Is it the undocumented config, or the lack of an error when setting CLP with a 40 character userID?

@flovilmart
Copy link
Contributor

I would say both, that we have a regex clearly not failing, and not documenting the option.

@addisonElliott
Copy link
Contributor

I believe there is a bug with the Postgres storage adapter and objectID's greater than 10.

If you look at PostgresStorageAdapter#L28, the Pointer postgres type is set to char(10). The 10 is hardcoded for length-10 object IDs but this will need to be dependent on the objectIdSize.

@montymxb
Copy link
Contributor

montymxb commented Dec 2, 2017

Hmmm, we'll want to open a PR for these issues soon and add some in-depth tests to make sure we don't have any issues with variable objectId field lengths, but in validation and in storage (postgres).

@johndoehelloworld
Copy link

I tried setting "objectIdSize", but the server crashed with the following error:

error: Error generating response. TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) error: Uncaught internal server error. TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) error: Error generating response. TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) error: Uncaught internal server error. TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) error: Error generating response. TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) error: Uncaught internal server error. TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) error: Error generating response. TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) error: Uncaught internal server error. TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) error: Error generating response. TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) error: Uncaught internal server error. TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7) Parse.Cloud.createGroup(): Error error: Failed running cloud function createGroup for user x45Zab1wtk with: Input: {} Error: {"code":141,"message":{"code":1}} error: Error generating response. ParseError { code: 141, message: ParseError { code: 1, message: undefined } } code=141, code=1, message=undefined error: ParseError { code: 1, message: undefined } code=141, code=1, message=undefined TypeError: size must be a number >= 0 at randomString (file/path/node_modules/parse-server/lib/cryptoUtils.js:39:41) at Object.newObjectId (file/path/node_modules/parse-server/lib/cryptoUtils.js:48:10) at RestWrite.setRequiredFieldsIfNeeded (file/path/node_modules/parse-server/lib/RestWrite.js:208:42) at Promise.resolve.then.then.then.then.then.then.then.then (file/path/node_modules/parse-server/lib/RestWrite.js:97:17) at process._tickDomainCallback (internal/process/next_tick.js:135:7)

Works fine when I remove the objectIdSize config – thoughts?

@flovilmart
Copy link
Contributor

It should be a number; what / how did you set this value?

@johndoehelloworld
Copy link

As an environment variable just as I add other configuration parameters while starting the server. Set it at 34.

@flovilmart
Copy link
Contributor

This is why it’s not properly mapped as a number probably.

@flovilmart
Copy link
Contributor

@johndoehelloworld what version of parse-server are your running&

@johndoehelloworld
Copy link

You were right @flovilmart – typecasting worked. Thanks for your prompt response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

6 participants