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

Invaliding Secure Cookie handling with localhost #1308

Closed
2 tasks done
Oliver-Fish opened this issue Mar 1, 2022 · 1 comment · Fixed by #1327
Closed
2 tasks done

Invaliding Secure Cookie handling with localhost #1308

Oliver-Fish opened this issue Mar 1, 2022 · 1 comment · Fixed by #1327
Labels
bug Something isn't working

Comments

@Oliver-Fish
Copy link

Checklist

  • I've searched for similar issues.
  • I'm using the latest version of HTTPie.

Minimal reproduction code and steps

Given the following tiny Go HTTP server

package main

import (
	"net/http"
)

func set(rw http.ResponseWriter, _ *http.Request) {
	http.SetCookie(rw, &http.Cookie{
		Name:     "session-token",
		Value:    "token here",
		Secure:   true,
		HttpOnly: false,
		SameSite: http.SameSiteNoneMode,
	})
	rw.Write(nil)
}

func get(rw http.ResponseWriter, req *http.Request) {
	cookie, err := req.Cookie("session-token")
	if err != nil {
		rw.Write(nil)
		return
	}
	rw.Write([]byte(cookie.Value))
}

func main() {
	http.HandleFunc("/set-cookie", set)
	http.HandleFunc("/get-cookie", get)

	panic(http.ListenAndServe(":8090", nil))
}

If you set the cookie to a session with the following command

http --session=./session.json GET http://localhost:8090/set-cookie

I would expect to be able to get the cookie value by the next running

http --session=./session.json GET http://localhost:8090/get-cookie

However, the cookie is unset in the second request if the Secure flag is set to true.

As per the spec;
A cookie with the Secure attribute is only sent to the server with an encrypted request over the HTTPS protocol. It's never sent with unsecured HTTP (except on localhost), which means man-in-the-middle attackers can't access it easily. (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies)

This appears to be mishandled in httpie, as it is not sending secure cookies when localhost is used.

Expected Behavior

Secure cookies are sent in localhost requests even if https is not in use

Actual Behavior

Secure cookies are not set

@Oliver-Fish Oliver-Fish added bug Something isn't working new Needs triage. Comments are welcome! labels Mar 1, 2022
@isidentical isidentical removed the new Needs triage. Comments are welcome! label Mar 1, 2022
@isidentical
Copy link
Contributor

Thanks for the report @Oliver-Fish, we are looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants