diff --git a/cloudflare/worker.js b/cloudflare/worker.js index 7c3150778b..32b3044951 100644 --- a/cloudflare/worker.js +++ b/cloudflare/worker.js @@ -11,7 +11,7 @@ const CUSTOM_OPTIONS = { APIKEY: '', Go_Proxy_BingAI_BLANK_API_KEY: false, - Go_Proxy_BingAI_AUTH_KEY: '', + Go_Proxy_BingAI_AUTH_KEYS: '', INFO: '', NIGHTLY: false, @@ -426,7 +426,7 @@ export default { CUSTOM_OPTIONS.Go_Proxy_BingAI_BLANK_API_KEY = (env.Go_Proxy_BingAI_BLANK_API_KEY != '' && env.Go_Proxy_BingAI_BLANK_API_KEY != undefined &&env.Go_Proxy_BingAI_BLANK_API_KEY != null); CUSTOM_OPTIONS.INFO = env.INFO || ''; CUSTOM_OPTIONS.NIGHTLY = (env.NIGHTLY != '' && env.NIGHTLY != undefined && env.NIGHTLY != null); - CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEY = env.Go_Proxy_BingAI_AUTH_KEY || ''; + CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEYS = env.Go_Proxy_BingAI_AUTH_KEY.split(',') || ''; const currentUrl = new URL(request.url); if (WEB_CONFIG.WORKER_URL == '') { @@ -438,7 +438,7 @@ export default { } if (currentUrl.pathname.startsWith('/sysconf')) { let isAuth = true; - if (CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEY.length !== 0) { + if (CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEYS.length !== 0) { const cookieStr = request.headers.get('Cookie') || ''; let cookieObjects = {}; cookieStr.split(';').forEach(item => { @@ -450,7 +450,7 @@ export default { const val = arr.slice(1, arr.length+1).join('=').trim(); cookieObjects[key] = val; }) - if (cookieObjects[AUTH_KEY_COOKIE_NAME] !== CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEY) { + if (CUSTOM_OPTIONS.Go_Proxy_BingAI_AUTH_KEYS.indexOf(cookieObjects[AUTH_KEY_COOKIE_NAME]) === -1) { isAuth = false; } } diff --git a/common/api/v1/func.go b/common/api/v1/func.go index 3852ff319b..eb59de1fc3 100644 --- a/common/api/v1/func.go +++ b/common/api/v1/func.go @@ -35,8 +35,8 @@ func init() { func getCookie(reqCookie, convId, rid string) (cookie string, err error) { cookie = reqCookie - if common.AUTH_KEY != "" { - cookie += "; " + common.AUTH_KEY_COOKIE_NAME + "=" + common.AUTH_KEY + if len(common.AUTH_KEYS) > 0 { + cookie += "; " + common.AUTH_KEY_COOKIE_NAME + "=" + common.AUTH_KEYS[0] } c := request.NewRequest() res := c.SetUrl("http://localhost:"+common.PORT+"/chat?q=Bing+AI&showconv=1&FORM=hpcodx&ajaxhist=0&ajaxserp=0&cc=us"). @@ -65,8 +65,8 @@ func getCookie(reqCookie, convId, rid string) (cookie string, err error) { if len(common.USER_TOKEN_LIST) == 0 { cookie += "; _U=" + hex.NewHex(128) } - if common.AUTH_KEY != "" { - cookie += "; " + common.AUTH_KEY_COOKIE_NAME + "=" + common.AUTH_KEY + if len(common.AUTH_KEYS) > 0 { + cookie += "; " + common.AUTH_KEY_COOKIE_NAME + "=" + common.AUTH_KEYS[0] } return cookie, nil } diff --git a/common/env.go b/common/env.go index 1d99d1b95a..3acff28f24 100644 --- a/common/env.go +++ b/common/env.go @@ -21,7 +21,7 @@ var ( USER_RwBf string USER_MUID string // 访问权限密钥,可选 - AUTH_KEY string + AUTH_KEYS []string AUTH_KEY_COOKIE_NAME = "BingAI_Auth_Key" BypassServer string @@ -56,7 +56,7 @@ func initEnv() { // is debug IS_DEBUG_MODE = os.Getenv("Go_Proxy_BingAI_Debug") != "" // auth - AUTH_KEY = os.Getenv("Go_Proxy_BingAI_AUTH_KEY") + AUTH_KEYS = strings.Split(os.Getenv("Go_Proxy_BingAI_AUTH_KEY"), ",") // KievRPSSecAuth Cookie USER_KievRPSSecAuth = os.Getenv("USER_KievRPSSecAuth") // MUID Cookie diff --git a/common/helper/helper.go b/common/helper/helper.go index c6e602434d..3888c4ae83 100644 --- a/common/helper/helper.go +++ b/common/helper/helper.go @@ -41,9 +41,9 @@ func UnauthorizedResult(w http.ResponseWriter) error { func CheckAuth(r *http.Request) bool { isAuth := true - if len(common.AUTH_KEY) > 0 { + if len(common.AUTH_KEYS) > 0 { ckAuthKey, _ := r.Cookie(common.AUTH_KEY_COOKIE_NAME) - isAuth = ckAuthKey != nil && len(ckAuthKey.Value) > 0 && common.AUTH_KEY == ckAuthKey.Value + isAuth = ckAuthKey != nil && len(ckAuthKey.Value) > 0 && common.IsInArray(common.AUTH_KEYS, ckAuthKey.Value) } return isAuth }