You've already forked agentic-coding-workflow
fix(user): withoutcancel audit, x-forwarded-for client ip
This commit is contained in:
@@ -77,9 +77,12 @@ func (s *service) Login(ctx context.Context, email, password, ip string) (string
|
||||
return "", nil, err
|
||||
}
|
||||
// 审计是 best-effort:_ = 吞掉错误,审计落库失败不能导致登录失败。
|
||||
// 用 context.WithoutCancel 派生:HTTP handler 在响应返回后 r.Context() 会
|
||||
// 被取消,但审计写入必须完成(漏行比写错更危险)。timeout 由调用方在
|
||||
// ctx 上不再控制,audit recorder 自身需保证不无限阻塞。
|
||||
if s.audit != nil {
|
||||
uid := u.ID
|
||||
_ = s.audit.Record(ctx, audit.Entry{
|
||||
_ = s.audit.Record(context.WithoutCancel(ctx), audit.Entry{
|
||||
UserID: &uid,
|
||||
Action: "user.login",
|
||||
TargetType: "user",
|
||||
@@ -102,9 +105,12 @@ func (s *service) Logout(ctx context.Context, token string) error {
|
||||
return err
|
||||
}
|
||||
// 审计是 best-effort:_ = 吞掉错误;uid == uuid.Nil 表示 token 无效,跳过。
|
||||
// 用 context.WithoutCancel 派生:HTTP handler 在响应返回后 r.Context() 会
|
||||
// 被取消,但审计写入必须完成(漏行比写错更危险)。timeout 由调用方在
|
||||
// ctx 上不再控制,audit recorder 自身需保证不无限阻塞。
|
||||
if s.audit != nil && uid != uuid.Nil {
|
||||
u := uid
|
||||
_ = s.audit.Record(ctx, audit.Entry{
|
||||
_ = s.audit.Record(context.WithoutCancel(ctx), audit.Entry{
|
||||
UserID: &u,
|
||||
Action: "user.logout",
|
||||
TargetType: "user",
|
||||
|
||||
Reference in New Issue
Block a user