Skip to content

Added support for secure and HttpOnly cookies#456

Open
rasulsafa wants to merge 6 commits intoNanoHttpd:masterfrom
rasulsafa:master
Open

Added support for secure and HttpOnly cookies#456
rasulsafa wants to merge 6 commits intoNanoHttpd:masterfrom
rasulsafa:master

Conversation

@rasulsafa
Copy link
Copy Markdown

No description provided.

@rasulsafa rasulsafa closed this Aug 26, 2017
@meisser
Copy link
Copy Markdown

meisser commented Jun 11, 2020

Why is this closed?

I'd love to see this.

@rasulsafa
Copy link
Copy Markdown
Author

Hm, I made this pull request almost three years ago - I don't really remember why I closed it. I'll make a small tweak and reopen it.

@rasulsafa rasulsafa reopened this Jun 11, 2020
@rasulsafa
Copy link
Copy Markdown
Author

I don't have time to test this until the weekend so if you or someone else would like to that would be great.

@luziusmeisser
Copy link
Copy Markdown

Thanks for reactivating. I got the cookies working, but it was a very painful experience. There are many things that need to be done just right in order for a modern browser to accept the cookie in a cross-site environment.

For those who are interested in what it takes besides setting the secure flag:

		res.addHeader("Access-Control-Allow-Origin", session.getHeaders().get("origin"));
		res.addHeader("Access-Control-Allow-Credentials", "true");

And then of course you also need to handle the pre-flight OPTION request:

if (session.getMethod() == Method.OPTIONS) {
Response resp = NanoHTTPD.newFixedLengthResponse("");
resp.addHeader("Access-Control-Allow-Methods", "OPTIONS, POST, GET";
resp.addHeader("Access-Control-Allow-Headers", "X-PINGOTHER, Content-Type");
return resp;
}

Furthermore, the browser might demand the domain to be set in the cookie.

All in all, it takes much more than just the secure flag to get it working. But I'm not sure inhowfar NanoHTTPD should support it. Its not called MicroHTTPD after all. :)

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

Successfully merging this pull request may close these issues.

3 participants