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

{"statusCode":400,"error":"Bad Request","message":"Invalid cookie value"} #58

Closed
madrus opened this issue Jul 25, 2016 · 3 comments
Closed

Comments

@madrus
Copy link

madrus commented Jul 25, 2016

The Cookies challenge has proved for me to be the most tricky challenge. I am still not sure that
I have got it right for my taste. Because of the stated cookie parsing error.

Note that these config options are only set for the /set-cookie route:

config: {
    state: {
        parse: true,
        failAction: 'log'
    }
}

After reading the Hapi docs about cookie parsing, I would actually expect it to be present on the /check-cookie route in the first place as that route is responsible for the cookie validation.

However, adding it to the the /check-cookie route invalidated the official verify.

So, I have also added the recommended error handler for cookie parsing problems:

server.on('request-internal', (request, event, tags) => {
    if (tags.error && tags.state) {
        console.error("Error parsing cookie:\n", event.data);
    }
});

Now, I could get a more detailed information of the cookie parsing error.

Your submission results compared to the expected:

───────────────────────────────────────────────────────────────
1.  ACTUAL:    "[\"session=eyJrZXkiOiJtYWtlbWVoYXBpIn0=; Max-Age=0; Expires=Mon, 25 Jul 2016 11:23:27 GMT; Domain=localhost; Path=/\"]"
1.  EXPECTED:  "[\"session=eyJrZXkiOiJtYWtlbWVoYXBpIn0=; Max-Age=0; Expires=Mon, 25 Jul 2016 11:23:27 GMT; Domain=localhost; Path=/\"]"

Error parsing cookie:
 { header: 'session=eyJrZXkiOiJtYWtlbWVoYXBpIn0=; Max-Age=0; Expires=Mon, 25 Jul 2016 11:23:27 GMT; Domain=localhost; Path=/',
  errors:
   [ { name: 'Expires',
       value: 'Mon, 25 Jul 2016 11:23:27 GMT',
       settings: [Object],
       reason: 'Invalid cookie value' } ] }
2.  ACTUAL:    "{\"user\":\"hapi\"}"
2.  EXPECTED:  "{\"statusCode\":400,\"error\":\"Bad Request\",\"message\":\"Invalid cookie value\"}"

───────────────────────────────────────────────────────────────
 Submission results did not match expected

# FAIL

Your solution to COOKIES didnt pass. Try again

It looks like the Expires key has an invalid datetime value although it looks perfectly ok to me.
Is this a bug or is it by design?

@pfurini
Copy link

pfurini commented Aug 9, 2016

I had the exactly same error, using latest hapi 14.1.0.
It seems the Expires key gets an invalid value.. I don't know if that challenge worked before, but a 10 ms ttl (that governs the Expires value) seems unreasonable to me. Both the legacy Expires setting and the newer Max-Age one have a precision of 1 second, so how can u set it to 10 ms?

I think this is a bug in the exercise, ttl should be set to at least 1000 ms..

@HelloYie
Copy link

HelloYie commented Aug 3, 2017

@madrus
Hi,
Maybe you cookie format is not RFC 6265.

So,

const server = new Hapi.Server({
  connections: {
    state: {
      // If your cookie format is not RFC 6265, set this param to false.
      strictHeader: false    
    }
  }
});

@amitdotagarwal
Copy link

amitdotagarwal commented May 12, 2018

Just clear browser cookie, it will work :) .

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

No branches or pull requests

5 participants