Skip to content

proto.NetworkCookie.Expires.Time should map -1 to a zero time value. #1159

Open
@kvii

Description

@kvii

Rod Version: v0.116.2

中文省流:如果在 rod cookie (a) 转 go http cookie (b) 的时候直接 b.Expires = a.Expires.Time() 的话,http 这边发请求时所有的 session cookie 就都没了。因为 rod session cookie 的值是 -1 而不是 0,转成 time 就成了 23:59:59 这样的值了。

proto.NetworkCookie.Expires(line 969) is a TimeSinceEpoch field.

rod/lib/proto/network.go

Lines 954 to 969 in 3025dde

// NetworkCookie Cookie object.
type NetworkCookie struct {
// Name Cookie name.
Name string `json:"name"`
// Value Cookie value.
Value string `json:"value"`
// Domain Cookie domain.
Domain string `json:"domain"`
// Path Cookie path.
Path string `json:"path"`
// Expires Cookie expiration date
Expires TimeSinceEpoch `json:"expires"`

TimeSinceEpoch.Time maps a TimeSinceEpoch value to time.Time value.

rod/lib/proto/a_patch.go

Lines 14 to 22 in 3025dde

// For session cookie, the value should be -1.
type TimeSinceEpoch float64
// Time interface.
func (t TimeSinceEpoch) Time() time.Time {
return (time.Unix(0, 0)).Add(
time.Duration(t * TimeSinceEpoch(time.Second)),
)
}

Please note the line 14, "For session cookie, the value should be -1. ". So when a cookie is a session cookie, the result will be unix(0) - 1("1969-12-31 23:59:59"). When you are using some codes like below:

func CookieFrom(c *proto.NetworkCookie) *http.Cookie {
	hc := &http.Cookie{
		Name:        c.Name,
		Value:       c.Value,
		Quoted:      false,
		Path:        c.Path,
		Domain:      c.Domain,
		Expires:     c.Expires.Time(), // <--
		RawExpires:  "",
		MaxAge:      0,
		Secure:      c.Secure,
		HttpOnly:    c.HTTPOnly,
		SameSite:    SameSite(c.SameSite),
		Partitioned: false,
		Raw:         "",
		Unparsed:    []string{},
	}
	return hc
}

You will loss all session cookie when you're sending requests. Because hc.Expires is not a zero value and it has expired.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhanceNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions