feat(web): W-G14 anlian-mq acceptance and auth/session listen fixes
Add a GFM-first anlian rewrite under examples/anlian-mq to exercise Go libweb (lists, detail, gates, login, WS). Wire RBAC/login into listen, page query/order/detail ABIs, and stop issuing Max-Age=0 CSRF cookies so browser login sessions stick. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e20cf8b386
commit
ce195998c1
22 files changed
+1454
-20
No files matched your search
@@ -537,7 +537,15 @@ func ValidateCSRF(id, token string) bool {
|
||||
}
|
||||
|
||||
// SessionCookie builds Set-Cookie for marqdo_sid.
|
||||
// ttlSec 0 means the configured default (never Max-Age=0 — that clears cookies;
|
||||
// use ClearCookie for logout).
|
||||
func SessionCookie(id string, ttlSec uint64, secure bool) string {
|
||||
if ttlSec == 0 {
|
||||
ttlSec = getCfg().TTLSec
|
||||
if ttlSec == 0 {
|
||||
ttlSec = defaultTTL
|
||||
}
|
||||
}
|
||||
s := fmt.Sprintf("marqdo_sid=%s; HttpOnly; Path=/; SameSite=Lax; Max-Age=%d", id, ttlSec)
|
||||
if secure {
|
||||
s += "; Secure"
|
||||
@@ -545,6 +553,17 @@ func SessionCookie(id string, ttlSec uint64, secure bool) string {
|
||||
return s
|
||||
}
|
||||
|
||||
// IssueCookie builds Set-Cookie using Configure'd TTL and CookieSecure.
|
||||
func IssueCookie(id string) string {
|
||||
c := getCfg()
|
||||
return SessionCookie(id, c.TTLSec, c.CookieSecure)
|
||||
}
|
||||
|
||||
// ClearCookie is the Set-Cookie value that expires marqdo_sid immediately.
|
||||
func ClearCookie() string {
|
||||
return "marqdo_sid=; HttpOnly; Path=/; Max-Age=0; SameSite=Lax"
|
||||
}
|
||||
|
||||
// IDFromCookie parses marqdo_sid from a Cookie header.
|
||||
func IDFromCookie(cookieHeader string) (string, bool) {
|
||||
if cookieHeader == "" {
|
||||
@@ -574,6 +593,25 @@ func ParseRolesCSV(raw string) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// RoleFromCookie returns session role (visitor when anonymous or missing).
|
||||
func RoleFromCookie(cookieHeader string) string {
|
||||
sid, ok := IDFromCookie(cookieHeader)
|
||||
if !ok {
|
||||
return "visitor"
|
||||
}
|
||||
if v, ok := GetValue(sid, "role"); ok {
|
||||
if s, ok := v.(string); ok && s != "" {
|
||||
return strings.ToLower(s)
|
||||
}
|
||||
}
|
||||
if v, ok := GetValue(sid, "username"); ok {
|
||||
if s, ok := v.(string); ok && s != "" {
|
||||
return "admin"
|
||||
}
|
||||
}
|
||||
return "visitor"
|
||||
}
|
||||
|
||||
// RoleAllowed reports whether role is in allowed (empty allowed = all).
|
||||
func RoleAllowed(role string, allowed []string) bool {
|
||||
if len(allowed) == 0 {
|
||||
|
||||
Reference in new issue
Block a user