mirror of
https://github.com/kataras/iris.git
synced 2026-02-11 13:15:56 +00:00
enhanced cookie security and management
Former-commit-id: a97b0b33e87749a2e8c32e63269fcc60fa326ff3
This commit is contained in:
@@ -13,33 +13,6 @@ const (
|
||||
DefaultCookieName = "irissessionid"
|
||||
)
|
||||
|
||||
// Encoding is the Cookie Encoder/Decoder interface, which can be passed as configuration field
|
||||
// alternatively to the `Encode` and `Decode` fields.
|
||||
type Encoding interface {
|
||||
// Encode the cookie value if not nil.
|
||||
// Should accept as first argument the cookie name (config.Name)
|
||||
// as second argument the server's generated session id.
|
||||
// Should return the new session id, if error the session id set to empty which is invalid.
|
||||
//
|
||||
// Note: Errors are not printed, so you have to know what you're doing,
|
||||
// and remember: if you use AES it only supports key sizes of 16, 24 or 32 bytes.
|
||||
// You either need to provide exactly that amount or you derive the key from what you type in.
|
||||
//
|
||||
// Defaults to nil
|
||||
Encode(cookieName string, value interface{}) (string, error)
|
||||
// Decode the cookie value if not nil.
|
||||
// Should accept as first argument the cookie name (config.Name)
|
||||
// as second second accepts the client's cookie value (the encoded session id).
|
||||
// Should return an error if decode operation failed.
|
||||
//
|
||||
// Note: Errors are not printed, so you have to know what you're doing,
|
||||
// and remember: if you use AES it only supports key sizes of 16, 24 or 32 bytes.
|
||||
// You either need to provide exactly that amount or you derive the key from what you type in.
|
||||
//
|
||||
// Defaults to nil
|
||||
Decode(cookieName string, cookieValue string, v interface{}) error
|
||||
}
|
||||
|
||||
type (
|
||||
// Config is the configuration for sessions. Please read it before using sessions.
|
||||
Config struct {
|
||||
@@ -66,34 +39,11 @@ type (
|
||||
// Defaults to false.
|
||||
AllowReclaim bool
|
||||
|
||||
// Encode the cookie value if not nil.
|
||||
// Should accept as first argument the cookie name (config.Cookie)
|
||||
// as second argument the server's generated session id.
|
||||
// Should return the new session id, if error the session id set to empty which is invalid.
|
||||
//
|
||||
// Note: Errors are not printed, so you have to know what you're doing,
|
||||
// and remember: if you use AES it only supports key sizes of 16, 24 or 32 bytes.
|
||||
// You either need to provide exactly that amount or you derive the key from what you type in.
|
||||
// Encoding should encodes and decodes
|
||||
// authenticated and optionally encrypted cookie values.
|
||||
//
|
||||
// Defaults to nil.
|
||||
Encode func(cookieName string, value interface{}) (string, error)
|
||||
// Decode the cookie value if not nil.
|
||||
// Should accept as first argument the cookie name (config.Cookie)
|
||||
// as second second accepts the client's cookie value (the encoded session id).
|
||||
// Should return an error if decode operation failed.
|
||||
//
|
||||
// Note: Errors are not printed, so you have to know what you're doing,
|
||||
// and remember: if you use AES it only supports key sizes of 16, 24 or 32 bytes.
|
||||
// You either need to provide exactly that amount or you derive the key from what you type in.
|
||||
//
|
||||
// Defaults to nil.
|
||||
Decode func(cookieName string, cookieValue string, v interface{}) error
|
||||
|
||||
// Encoding same as Encode and Decode but receives a single instance which
|
||||
// completes the "CookieEncoder" interface, `Encode` and `Decode` functions.
|
||||
//
|
||||
// Defaults to nil.
|
||||
Encoding Encoding
|
||||
Encoding context.SecureCookie
|
||||
|
||||
// Expires the duration of which the cookie must expires (created_time.Add(Expires)).
|
||||
// If you want to delete the cookie when the browser closes, set it to -1.
|
||||
@@ -131,10 +81,5 @@ func (c Config) Validate() Config {
|
||||
}
|
||||
}
|
||||
|
||||
if c.Encoding != nil {
|
||||
c.Encode = c.Encoding.Encode
|
||||
c.Decode = c.Encoding.Decode
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user