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

Validate messages on the backend #15

Open
3 tasks
karranb opened this issue Oct 9, 2022 · 4 comments
Open
3 tasks

Validate messages on the backend #15

karranb opened this issue Oct 9, 2022 · 4 comments
Labels

Comments

@karranb
Copy link
Owner

karranb commented Oct 9, 2022

Using a package like Zod, validate the messages send by the socket clients to the socket server, returning UNPROCESSED message when a message is invalid.

EG:

Create expected message parser and type

const SetUsernameMessage = z.object({
  name: z.string(),
  version: z.string(),
  countryCode: z.string().optional(),
});

type SetUsernameMessage = z.infer<typeof SetUsernameMessage>;

validate received unknown message

handleSetUserName(socket: Socket, message: unknown): void {
      ...
      const result = SetUsernameMessage.safeParse(message)
      if (result.success === false) {
        throw new SocketError('Invalid message')
      }
      const { name, version, countryCode } = result.data
      ...
}
  • Room (node_server/src/core/game/mixins/room.ts)
  • Challenge (node_server/src/core/game/mixins/challenge.ts)
  • Game (node_server/src/core/game/mixins/game.ts)
@khanhtranngoccva
Copy link

Hi there! I would like to be assigned this issue and try to work on it!

@karranb
Copy link
Owner Author

karranb commented Oct 26, 2022

nice! feel free to ping me if you need any help =)

@khanhtranngoccva
Copy link

Hey there @karranb, I'd love how I can get the example of a typical message argument in each of the method you want to change, since it might take weeks to familiarize with the codebase.

@khanhtranngoccva
Copy link

khanhtranngoccva commented Oct 26, 2022

By the way, I could not run the front-end to test your software and what it sends. I already ran "yarn install" and the runtime reports "process" not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants