Skip to content

BadRequestError: checks.state argument is missing when routing between pages using browser's back button #625

@link01153113

Description

@link01153113

Checklist

Description

I have multiple apps using the same domain with the same login system (Cognito). When navigating directly to a page, there are no issues. However, if I navigate to the first page, then go to the second page, and finally click the browser's back button to return to the first page, I always encounter a BadRequestError.

BadRequestError: checks.state argument is missing
    at ResponseContext.callback (/home/node_modules/express-openid-connect/lib/context.js:354:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

It only happens on v2 express-openid-connect, but not on v1.
App using v2 is able to return to app using v1 without issue using browser's back button. Somehow it only happens in v2.
Is it the desired behavior or am I overlooking something? Thank you for your time.

Reproduction

  1. Login to the portal
  2. Route to the first page
  3. Route to the second page
  4. Click browser's back button to return to the first page.
  5. Error shows up

One of the apps setup:

server.use(
        auth({
            authRequired: true,
            issuerBaseURL: `https://cognito-idp.us-east-1.amazonaws.com/${process.env.USER_POOL_ID}`,
            baseURL,
            clientID: `${process.env.COGNITO_CLIENT_ID}`,
            clientSecret: `${process.env.COGNITO_CLIENT_SECRET}`,
            secret,
            authorizationParams: {
                response_type: "code",
                scope: "openid profile",
            },
            routes: {
                postLogoutRedirect: `https://${process.env.COGNITO_USER_POOL_DOMAIN}/logout?client_id=${process.env.COGNITO_CLIENT_ID}&logout_uri=${baseUrl}`,
            },
            afterCallback: async function (req, res, session, decodedState) {
                try {
                    return session;
                } catch (err) {
                    console.error(
                        "There was a problem after auth callback: ",
                        err
                    );
                    return session;
                }
            },
        })
    );

Additional context

No response

express-openid-connect version

2.17.1

Express version

4.18.2

Node.js version

16

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions