Browse Source

:art: Authenticate requests with the Origin header other than 127.0.0.1 https://github.com/siyuan-note/siyuan/issues/9180

Daniel 1 year ago
parent
commit
0e7dcc0ea1
1 changed files with 15 additions and 6 deletions
  1. 15 6
      kernel/model/session.go

+ 15 - 6
kernel/model/session.go

@@ -165,12 +165,21 @@ func CheckAuth(c *gin.Context) {
 			u, parseErr := url.Parse(origin)
 			if nil != parseErr {
 				logging.LogWarnf("parse origin [%s] failed: %s", origin, parseErr)
-			} else {
-				if !strings.HasPrefix(u.Host, util.LocalHost) && !strings.HasPrefix(u.Host, "[::1]") {
-					c.JSON(401, map[string]interface{}{"code": -1, "msg": "Auth failed"})
-					c.Abort()
-					return
-				}
+				c.JSON(401, map[string]interface{}{"code": -1, "msg": "Auth failed"})
+				c.Abort()
+				return
+
+			}
+
+			if "chrome-extension" == strings.ToLower(u.Scheme) {
+				c.Next()
+				return
+			}
+
+			if !strings.HasPrefix(u.Host, util.LocalHost) && !strings.HasPrefix(u.Host, "[::1]") {
+				c.JSON(401, map[string]interface{}{"code": -1, "msg": "Auth failed"})
+				c.Abort()
+				return
 			}
 		}