From ebe5733f27301d24a80eae4e1962753687039fcd Mon Sep 17 00:00:00 2001 From: Daniel Jiang Date: Tue, 18 May 2021 14:54:58 +0800 Subject: [PATCH] Check user in security context before getting the ID This commit fix a potential nil pointer issue when trying to read User ID from security context Signed-off-by: Daniel Jiang --- src/controller/user/controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/user/controller.go b/src/controller/user/controller.go index d646a61ea..1b3576b76 100644 --- a/src/controller/user/controller.go +++ b/src/controller/user/controller.go @@ -113,7 +113,7 @@ func (c *controller) Get(ctx context.Context, id int, opt *Option) (*models.User return nil, fmt.Errorf("can't find security context") } lsc, ok := sctx.(*local.SecurityContext) - if ok && lsc.User().UserID == id { + if ok && lsc.User() != nil && lsc.User().UserID == id { u.AdminRoleInAuth = lsc.User().AdminRoleInAuth } if opt != nil && opt.WithOIDCInfo {