Skip to content

change userInfo table #646

Closed
Closed

Description

@ramyak-mehra

Is your feature request related to a problem? Please describe.
Is there a way to change the default userInfo table? I basically want to use uuid instead of int as ids.
Its sort of a security bug that its user guessable

Describe the solution you'd like
Not use userInfo object and just extend it, but that would mean rewriting a custom auth .

Activity

  1. yahu1031 commented on Feb 12, 2023

    @yahu1031
    Contributor

    The enhancement was already merged, need to make a release.

  2. fischerscode commented on Feb 12, 2023

    @fischerscode
    Contributor

    Maybe I'm missing something, but #641 just added support for using UUIDs in the protocol specification. There is currently no change to the userInfo table or the auth module. changes

  3. ramyak-mehra commented on Feb 12, 2023

    @ramyak-mehra
    Author

    Yeah I checked that, It just adds the option to do use uuid field, and not change it. My main thing was to be able to override id field coz you see I could use a string to represent the uuid, but I can't change it id field is set by default. If this is something you wanted to support and someone else is not working on it, I can pick this up.

    Proposed solution if id is provided in the field use that instead of generating a default one.

  4. fischerscode commented on Feb 12, 2023

    @fischerscode
    Contributor

    I THINK nobody is working on this.

    Proposed solution if id is provided in the field use that instead of generating a default one.

    This would be a nice feature, but I don't think this is enough, since the serverpod generate does not run in modules when you run it in your project. I think with the current logic something like this is only possible by forking the auth module, but I might be wrong about that.


    Using UUIDs as ids in userInfo should be equivalent to adding additional columns to tables / classes generated in modules. To support this, quite some refactoring should be required, but maybe @vlidholt has an idea.

  5. ramyak-mehra commented on Feb 12, 2023

    @ramyak-mehra
    Author

    ok so m not talking about specifically about userInfo table coz thats auto generated, but in general for any other table. Also I just started experimenting with it like a couple of days ago found It interesting so I thought why not give it a go. If you think I can tackle that id thing like a more general thing ill pick this up and try to make a PR.

  6. ramyak-mehra commented on Feb 12, 2023

    @ramyak-mehra
    Author

    any docs about the architecture in general would be kindaa helpful

  7. fischerscode commented on Feb 12, 2023

    @fischerscode
    Contributor

    Proposed solution if id is provided in the field use that instead of generating a default one.

    I think this would be nice to have, but @vlidholt would have to decide whether this is something he wants to have. (I'm just a contributor...)

    any docs about the architecture in general would be kindaa helpful

    I think there are none, but feel free to @mention me when you have a question, I think, I have a good overview of the generator part.

    I think the most relevant parts would be:

    • Make id generic:
      /// The id column of the row. Can be null if this row is not yet stored in
      /// the database.
      int? id;
    • // Add default id field, if object has database table.
      if (tableName != null) {
      fields.add(FieldDefinition(
      name: 'id',
      type: TypeDefinition.int.asNullable,
      scope: FieldScope.all,
      documentation: [
      '/// The database id, set if the object has been inserted into the',
      '/// database or if it has been fetched from the database. Otherwise,',
      '/// the id will be null.',
      ],
      ));
      }
    • classBuilder.extend =
      refer('TableRow', 'package:serverpod/serverpod.dart');
    • for (var field in fields) {
      if (field.shouldIncludeField(serverCode) &&
      !(field.name == 'id' && serverCode && tableName != null)) {
      classBuilder.fields.add(Field((f) {
      f.type = field.type.reference(serverCode,
      subDirectory: classDefinition.subDir);
      f
      ..name = field.name
      ..docs.addAll(field.documentation ?? []);
      }));
      }
      }
    • if (field.name == 'id' && serverCode && tableName != null) {
      c.optionalParameters.add(Parameter((p) {
      p.named = true;
      p.name = 'id';
      p.type = TypeReference(
      (t) => t
      ..symbol = 'int'
      ..isNullable = true,
      );
      }));
      } else {
      c.optionalParameters.add(Parameter((p) {
      p.named = true;
      p.required = !field.type.nullable;
      p.toThis = true;
      p.name = field.name;
      }));
      }
      }
    • findById:
      ..requiredParameters.addAll([
      Parameter((p) => p
      ..type =
      refer('Session', 'package:serverpod/serverpod.dart')
      ..name = 'session'),
      Parameter((p) => p
      ..type = refer('int')
      ..name = 'id'),
      ])
      ..modifier = MethodModifier.async
      ..body = refer('session')
      .property('db')
      .property('findById')
      .call([refer('id')], {}, [refer(className)])
      .returned
      .statement));

      (I'm missing parts for sure)
  8. ramyak-mehra commented on Feb 12, 2023

    @ramyak-mehra
    Author

    I think it should be pretty straight forward, Hey @vlidholt, if you give a green light I can work on this.

  9. ramyak-mehra commented on Feb 12, 2023

    @ramyak-mehra
    Author

    I have a very simple fix for it tbh, what if I make the TableRow class generic over T and use that instead of int, so not a lot of code change would be required and it would be pretty flexible too.

  10. fischerscode commented on Feb 12, 2023

    @fischerscode
    Contributor

    what if I make the TableRow class generic over T and use that instead of int, so not a lot of code change would be required and it would be pretty flexible too.

    In here?

    /// The id column of the row. Can be null if this row is not yet stored in
    /// the database.
    int? id;

    That's what I've done, too.


    Use this method to get the type reference later in the generator.

    /// Generate a [TypeReference] from this definition.
    TypeReference reference(
    bool serverCode, {
    bool? nullable,
    String? subDirectory,
    }) {

  11. ramyak-mehra commented on Feb 12, 2023

    @ramyak-mehra
    Author

    let me try to come up with a poc and then well see

  12. vlidholt commented on Feb 13, 2023

    @vlidholt
    Collaborator

    It's generally a good idea to use an int as the idea internally in the server for many reasons (this is what most sites, including big ones do). What is shown towards the client may be another issue. Having a UUID attached to a user can have certain uses, but another solution can also be to use a method that converts the id to a unique string using some encryption algorithm. The string can then be reverted back to an id if you have the key. There are libraries for this, just cannot remember the name from the top of my head.

  13. ramyak-mehra commented on Feb 13, 2023

    @ramyak-mehra
    Author

    so what I usually see int stored in the database as storage/ memory saving technique and can have performance difference too at some level, but I believe the current design is too opinionated. The default can be int but user should have the flexibility to use anything if required.

  14. momadvisor commented on Jun 18, 2024

    @momadvisor

    I deeply agree with you, @ramyak-mehra.

  15. SandPod commented on Dec 17, 2024

    @SandPod
    Contributor

    If I understand the conversation here correctly, the core of this issue is that user ids should not be guessable.

    Therefore, I'll close this as a duplicate of: #554
    If that issue is resolved, then this issue should also be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions