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

[DB Auth] Generated auth handlers do not handle base64 encoded requests #3270

Closed
dac09 opened this issue Aug 23, 2021 · 2 comments · Fixed by #3275
Closed

[DB Auth] Generated auth handlers do not handle base64 encoded requests #3270

dac09 opened this issue Aug 23, 2021 · 2 comments · Fixed by #3275
Assignees
Labels
bug/confirmed We have confirmed this is a bug topic/auth

Comments

@dac09
Copy link
Collaborator

dac09 commented Aug 23, 2021

What's the issue?

Originally reported by Jace on Discord. When the /login and /signup function handlers are deployed on vercel, it errors out with:

Expecting JSON error at char 0 'e'" 

Analysis

It seems this is because vercel base64 encodes incoming requests

Expected behaviour

The handlers should check if the event is base64 encoded, and decode it before continuing. (See example in comments)

@dac09 dac09 added bug/confirmed We have confirmed this is a bug topic/auth labels Aug 23, 2021
@dac09 dac09 added this to the next-release-patch milestone Aug 23, 2021
@redwoodjs-bot redwoodjs-bot bot added this to New issues in Current-Release-Sprint Aug 23, 2021
@dac09
Copy link
Collaborator Author

dac09 commented Aug 23, 2021

Here's an example of one of my handlers where I was handling a base64 encoded event.

try {
    if (event.isBase64Encoded) {
      const stringBody = Buffer.from(body as string, 'base64').toString('ascii')
      parsedBody = querystring.parse(
        stringBody
      ) as unknown as PaddleSubscriptionHook
    } else {
      parsedBody = querystring.parse(
        body as string
      ) as unknown as PaddleSubscriptionHook
    }

Types included for reference ;) - but we may not need to use the querystring library

@thedavidprice thedavidprice moved this from New issues to v0.37 in Current-Release-Sprint Aug 23, 2021
@dthyresson
Copy link
Contributor

This is an example used in graphql.ts:

/**
 * Extracts and parses body payload from event with base64 encoding check
 *
 */
const parseEventBody = (event: APIGatewayProxyEvent) => {
  if (event.isBase64Encoded) {
    return JSON.parse(Buffer.from(event.body || '', 'base64').toString('utf-8'))
  } else {
    return event.body && JSON.parse(event.body)
  }
}

cannikin added a commit that referenced this issue Aug 23, 2021
cannikin added a commit that referenced this issue Aug 25, 2021
* Handle base64 encoded event boy

Closes #3270

* Update types for username and password

* Fix all the squiggles with `value is string`

Co-authored-by: Rob Cameron <rob.cameron@fastmail.com>
thedavidprice pushed a commit that referenced this issue Aug 27, 2021
* Handle base64 encoded event boy

Closes #3270

* Update types for username and password

* Fix all the squiggles with `value is string`

Co-authored-by: Rob Cameron <rob.cameron@fastmail.com>
dthyresson added a commit that referenced this issue Aug 30, 2021
…ql handler (#3286)

* Rework api and graphql-server, tests + e2e pass

* Remove useEnvelop experimental flag

* Rework errors

* Rework api imports in graphql-server

* Remove ApolloServer references

* Update service generator for beforeResolver move

* Remove webhooks, logger from graphql-server

* Remove unused packages

* Move Global Context into graphql-server

* Update auto imports

* Updates type generation

* Removes corejs

* Changes context import in rootSchema

* Removes GlobalContext where not needed

* resolve rhf explicitly (#3291)

* Export redwood and prisma versions from api

* add RedwoodProvider to mockProviders for unit testing (#3269)

* dbAuth: Handle base64 encoded event body (#3275)

* Handle base64 encoded event boy

Closes #3270

* Update types for username and password

* Fix all the squiggles with `value is string`

Co-authored-by: Rob Cameron <rob.cameron@fastmail.com>

* resolve rhf explicitly (#3291)

* upgrade prisma v2.30.0 (#3290)

Co-authored-by: Vincent Choy <vchoy@ccrhub.com>
Co-authored-by: David Price <thedavid@thedavidprice.com>

* update yarn.lock

* v0.36.2

* update yarn.lock

* Try reconfiguring ts | Add reference to api from gql-server

Co-authored-by: Dominic Saadi <32992335+jtoar@users.noreply.github.com>
Co-authored-by: Simon Gagnon <simon@mu2.ca>
Co-authored-by: Rob Cameron <cannikin@fastmail.com>
Co-authored-by: Rob Cameron <rob.cameron@fastmail.com>
Co-authored-by: vchoy <vinchoy@gmail.com>
Co-authored-by: Vincent Choy <vchoy@ccrhub.com>
Co-authored-by: David Price <thedavid@thedavidprice.com>
Co-authored-by: Daniel Choudhury <dannychoudhury@gmail.com>
@thedavidprice thedavidprice removed this from the next-release-patch milestone Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/confirmed We have confirmed this is a bug topic/auth
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants