From 5a99b6000912ace4ad79b59179f2f60132a35762 Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:13:56 +0200 Subject: [PATCH 01/13] update go (+ modules) --- go.mod | 4 ++-- go.sum | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 9a932b8..62c830e 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/codeshelldev/secured-signal-api -go 1.24.4 +go 1.24.5 require go.uber.org/zap v1.27.0 -require go.uber.org/multierr v1.10.0 // indirect +require go.uber.org/multierr v1.11.0 // indirect diff --git a/go.sum b/go.sum index e1a34f3..9fe9a49 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,14 @@ -go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= -go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 76bcd824e7a74c9ef1394bf667b78fc2f46aafec Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:14:21 +0200 Subject: [PATCH 02/13] added general utils pckg --- utils/utils.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 utils/utils.go diff --git a/utils/utils.go b/utils/utils.go new file mode 100644 index 0000000..3ea28ff --- /dev/null +++ b/utils/utils.go @@ -0,0 +1,61 @@ +package utils + +/* + * General Functions (utils) + * Might move Functions into seperate files + */ + +import ( + "encoding/json" + "errors" + "regexp" + "strings" +) + +func StringToArray(sliceStr string) ([]string, error) { + if sliceStr == "" { + return []string{}, errors.New("sliceStr is empty") + } + + re, err := regexp.Compile(`\s+`) + + if err != nil { + return []string{}, err + } + + normalized := re.ReplaceAllString(sliceStr, "") + + tokens := strings.Split(normalized, ",") + + return tokens, nil +} + +func Contains[T comparable](list []T, item T) (bool){ + for _, match := range list { + if match == item { + return true + } + } + + return false +} + +func GetJsonSafe[T any](jsonStr string) (T, error) { + var result T + + err := json.Unmarshal([]byte(jsonStr), &result) + + return result, err +} + +func GetJson[T any](jsonStr string) (T) { + var result T + + err := json.Unmarshal([]byte(jsonStr), &result) + + if err != nil { + // JSON is empty + } + + return result +} \ No newline at end of file From e09033cf21deb60bc23215b28d811d775f3a473b Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:15:02 +0200 Subject: [PATCH 03/13] added functionallity for multiple API Tokens in `API_TOKEN` and `API_TOKENS` --- internals/proxy/middlewares/auth.go | 17 +++++--- main.go | 4 +- utils/env/env.go | 66 +++++++---------------------- 3 files changed, 29 insertions(+), 58 deletions(-) diff --git a/internals/proxy/middlewares/auth.go b/internals/proxy/middlewares/auth.go index aa00053..468a77f 100644 --- a/internals/proxy/middlewares/auth.go +++ b/internals/proxy/middlewares/auth.go @@ -6,12 +6,13 @@ import ( "net/url" "strings" + "github.com/codeshelldev/secured-signal-api/utils" log "github.com/codeshelldev/secured-signal-api/utils/logger" ) type AuthMiddleware struct { Next http.Handler - Token string + Tokens []string } type authType string @@ -34,12 +35,16 @@ func getAuthType(str string) authType { } } +func isValidToken(tokens []string, match string) (bool) { + return utils.Contains(tokens, match) +} + func (data AuthMiddleware) Use() http.Handler { next := data.Next - token := data.Token + tokens := data.Tokens return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - if token == "" { + if len(tokens) <= 0 { next.ServeHTTP(w, req) return } @@ -60,7 +65,7 @@ func (data AuthMiddleware) Use() http.Handler { switch authType { case Bearer: - if authToken == token { + if isValidToken(tokens, authToken) { success = true } @@ -76,7 +81,7 @@ func (data AuthMiddleware) Use() http.Handler { user := "api" - if basicAuthParams[0] == user && basicAuthParams[1] == token { + if basicAuthParams[0] == user && isValidToken(tokens, basicAuthParams[1]) { success = true } } @@ -86,7 +91,7 @@ func (data AuthMiddleware) Use() http.Handler { authToken, _ := url.QueryUnescape(authQuery) - if authToken == token { + if isValidToken(tokens, authToken) { success = true modifiedQuery := req.URL.Query() diff --git a/main.go b/main.go index ce776c0..c430634 100644 --- a/main.go +++ b/main.go @@ -42,8 +42,8 @@ func main() { } auth_m1 := AuthMiddleware{ - Next: endp_m2.Use(), - Token: ENV.API_TOKEN, + Next: endp_m2.Use(), + Tokens: ENV.API_TOKENS, } log_m0 := LogMiddleware{ diff --git a/utils/env/env.go b/utils/env/env.go index 8350229..01ba931 100644 --- a/utils/env/env.go +++ b/utils/env/env.go @@ -1,17 +1,17 @@ package env import ( - "encoding/json" "os" middlewares "github.com/codeshelldev/secured-signal-api/internals/proxy/middlewares" + "github.com/codeshelldev/secured-signal-api/utils" log "github.com/codeshelldev/secured-signal-api/utils/logger" ) type ENV_ struct { PORT string API_URL string - API_TOKEN string + API_TOKENS []string BLOCKED_ENDPOINTS []string VARIABLES map[string]any MESSAGE_ALIASES []middlewares.MessageAlias @@ -76,7 +76,11 @@ func Load() { ENV.PORT = os.Getenv("PORT") ENV.API_URL = os.Getenv("SIGNAL_API_URL") - ENV.API_TOKEN = os.Getenv("API_TOKEN") + apiToken := os.Getenv("API_TOKENS") + + if apiToken == "" { + apiToken = os.Getenv("API_TOKEN") + } blockedEndpointJSON := os.Getenv("BLOCKED_ENDPOINTS") recipientsJSON := os.Getenv("RECIPIENTS") @@ -85,59 +89,21 @@ func Load() { log.Info("Loaded Environment Variables") - if ENV.API_TOKEN == "" { + apiTokens, err := utils.StringToArray(apiToken) + + if err != nil { log.Warn("No API TOKEN provided this is NOT recommended") log.Info("Disabling Security Features due to incomplete Congfiguration") ENV.BLOCKED_ENDPOINTS = []string{} + } else { + ENV.API_TOKENS = apiTokens } - if blockedEndpointJSON != "" { - var blockedEndpoints []string + ENV.BLOCKED_ENDPOINTS = utils.GetJson[[]string](blockedEndpointJSON) + ENV.MESSAGE_ALIASES = utils.GetJson[[]middlewares.MessageAlias](messageAliasesJSON) - err := json.Unmarshal([]byte(blockedEndpointJSON), &blockedEndpoints) - - if err != nil { - log.Error("Could not decode Blocked Endpoints: ", blockedEndpointJSON) - } - - ENV.BLOCKED_ENDPOINTS = blockedEndpoints - } - - if messageAliasesJSON != "" { - var msgAliases []middlewares.MessageAlias - - err := json.Unmarshal([]byte(messageAliasesJSON), &msgAliases) - - if err != nil { - log.Error("Could not decode Message Aliases ", variablesJSON) - } - - ENV.MESSAGE_ALIASES = msgAliases - } - - if variablesJSON != "" { - var variables map[string]interface{} - - err := json.Unmarshal([]byte(variablesJSON), &variables) - - if err != nil { - log.Error("Could not decode Variables ", variablesJSON) - } - - ENV.VARIABLES = variables - } - - if recipientsJSON != "" { - var recipients []string - - err := json.Unmarshal([]byte(recipientsJSON), &recipients) - - if err != nil { - log.Error("Could not decode Variables ", variablesJSON) - } - - ENV.VARIABLES["RECIPIENTS"] = recipients - } + ENV.VARIABLES = utils.GetJson[map[string]any](variablesJSON) + ENV.VARIABLES["RECIPIENTS"] = utils.GetJson[[]string](recipientsJSON) } \ No newline at end of file From bfa8f922480364f554c0d1e08f8464d84f6783cb Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:15:13 +0200 Subject: [PATCH 04/13] updated README to reflect changes --- .github/templates/README.template.md | 62 +++++++++++++++++----------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/.github/templates/README.template.md b/.github/templates/README.template.md index 84eff81..d27e16b 100644 --- a/.github/templates/README.template.md +++ b/.github/templates/README.template.md @@ -55,12 +55,12 @@ To use Basic Auth as Authorization Method add `Authorization: Basic BASE64_STRIN User is `api` (LOWERCASE) -Formatting for `BASE64_STRING` = `user:API_KEY`. +Formatting for `BASE64_STRING` = `user:API_TOKEN`. example: ```bash -echo "api:API_KEY" | base64 +echo "api:API_TOKEN" | base64 ``` => `YXBpOkFQSV9LRVkK` @@ -76,7 +76,7 @@ Here is a simple example: curl -X POST http://sec-signal-api:8880/v2/send?@authorization=API_TOKEN ``` -Notice the `@` infront of `authorization`. See [Formatting](#format) +Notice the `@` infront of `authorization`. See [Formatting](#format). ### Example @@ -121,9 +121,17 @@ http://sec-signal-api:8880/v1/receive/{{.NUMBER}} In some cases you may not be able to access / modify the Request Body, in that case specify needed values in the Request Query: -``` -http://sec-signal-api:8880/?@key=value -``` +Supported types include **strings**, **ints** and **arrays** + +`http://sec-signal-api:8880/?@key=value` + +| type | example | +| :--------- | :------ | +| string | abc | +| int | 123 | +| array | [1,2,3] | +| array(int) | 1,2,3 | +| array(str) | a,b,c | ##### Format @@ -132,14 +140,23 @@ you have to add `@` in front of any KeyValue Pair assignment. ### Environment Variables -#### API Token +#### API Token/s + +Both `API_TOKEN` and `API_TOKENS` support multiple Tokens seperated by **,**. +During Authentikcation Secured Signal API will try to match the given Token against the list of Tokens inside of these Variables. + +```yaml +environment: + API_TOKEN: "token1, token2, token3" + API_TOKENS: "token1, token2, token3" +``` > [!IMPORTANT] > It is highly recommended to set this Environment Variable > _What if I just don't?_ -Well, Secured Signal API will still work, but important Security Features won't be available +Secured Signal API will still work, but important Security Features won't be available like Blocked Endpoints and any sort of Auth. > [!NOTE] @@ -147,23 +164,18 @@ like Blocked Endpoints and any sort of Auth. #### Blocked Endpoints -Because Secured Signal API is just a secure Proxy you can use all of the [Signal REST API](https://github.com/bbernhard/signal-cli-rest-api/blob/master/doc/EXAMPLES.md) endpoints except for... - -- **/v1/about** - -- **/v1/configuration** - -- **/v1/devices** - -- **/v1/register** - -- **/v1/unregister** - -- **/v1/qrcodelink** - -- **/v1/accounts** - -- **/v1/contacts** +Because Secured Signal API is just a Proxy you can use all of the [Signal REST API](https://github.com/bbernhard/signal-cli-rest-api/blob/master/doc/EXAMPLES.md) endpoints except for... + +| Endpoint | +| :-------------------- | +| **/v1/about** | +| **/v1/configuration** | +| **/v1/devives** | +| **/v1/register** | +| **/v1/unregister** | +| **/v1/qrcodelink** | +| **/v1/accounts** | +| **/v1/contacts** | These Endpoints are blocked by default due to Security Risks, but can be modified by setting `BLOCKED_ENDPOINTS` to a valid json array string From c5e017c616e29683fe74e814f90cd5327f446f11 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 24 Aug 2025 15:15:24 +0000 Subject: [PATCH 05/13] Update README.md --- README.md | 62 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index ab2b0f7..9044c36 100644 --- a/README.md +++ b/README.md @@ -114,12 +114,12 @@ To use Basic Auth as Authorization Method add `Authorization: Basic BASE64_STRIN User is `api` (LOWERCASE) -Formatting for `BASE64_STRING` = `user:API_KEY`. +Formatting for `BASE64_STRING` = `user:API_TOKEN`. example: ```bash -echo "api:API_KEY" | base64 +echo "api:API_TOKEN" | base64 ``` => `YXBpOkFQSV9LRVkK` @@ -135,7 +135,7 @@ Here is a simple example: curl -X POST http://sec-signal-api:8880/v2/send?@authorization=API_TOKEN ``` -Notice the `@` infront of `authorization`. See [Formatting](#format) +Notice the `@` infront of `authorization`. See [Formatting](#format). ### Example @@ -180,9 +180,17 @@ http://sec-signal-api:8880/v1/receive/{{.NUMBER}} In some cases you may not be able to access / modify the Request Body, in that case specify needed values in the Request Query: -``` -http://sec-signal-api:8880/?@key=value -``` +Supported types include **strings**, **ints** and **arrays** + +`http://sec-signal-api:8880/?@key=value` + +| type | example | +| :--------- | :------ | +| string | abc | +| int | 123 | +| array | [1,2,3] | +| array(int) | 1,2,3 | +| array(str) | a,b,c | ##### Format @@ -191,14 +199,23 @@ you have to add `@` in front of any KeyValue Pair assignment. ### Environment Variables -#### API Token +#### API Token/s + +Both `API_TOKEN` and `API_TOKENS` support multiple Tokens seperated by **,**. +During Authentikcation Secured Signal API will try to match the given Token against the list of Tokens inside of these Variables. + +```yaml +environment: + API_TOKEN: "token1, token2, token3" + API_TOKENS: "token1, token2, token3" +``` > [!IMPORTANT] > It is highly recommended to set this Environment Variable > _What if I just don't?_ -Well, Secured Signal API will still work, but important Security Features won't be available +Secured Signal API will still work, but important Security Features won't be available like Blocked Endpoints and any sort of Auth. > [!NOTE] @@ -206,23 +223,18 @@ like Blocked Endpoints and any sort of Auth. #### Blocked Endpoints -Because Secured Signal API is just a secure Proxy you can use all of the [Signal REST API](https://github.com/bbernhard/signal-cli-rest-api/blob/master/doc/EXAMPLES.md) endpoints except for... - -- **/v1/about** - -- **/v1/configuration** - -- **/v1/devices** - -- **/v1/register** - -- **/v1/unregister** - -- **/v1/qrcodelink** - -- **/v1/accounts** - -- **/v1/contacts** +Because Secured Signal API is just a Proxy you can use all of the [Signal REST API](https://github.com/bbernhard/signal-cli-rest-api/blob/master/doc/EXAMPLES.md) endpoints except for... + +| Endpoint | +| :-------------------- | +| **/v1/about** | +| **/v1/configuration** | +| **/v1/devives** | +| **/v1/register** | +| **/v1/unregister** | +| **/v1/qrcodelink** | +| **/v1/accounts** | +| **/v1/contacts** | These Endpoints are blocked by default due to Security Risks, but can be modified by setting `BLOCKED_ENDPOINTS` to a valid json array string From 8b7c3a5697ff16487741ec348eb766d3d66c1e1c Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:22:57 +0200 Subject: [PATCH 06/13] go standard library has got you covered :) --- internals/proxy/middlewares/auth.go | 4 ++-- utils/utils.go | 10 ---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/internals/proxy/middlewares/auth.go b/internals/proxy/middlewares/auth.go index 468a77f..ba3417a 100644 --- a/internals/proxy/middlewares/auth.go +++ b/internals/proxy/middlewares/auth.go @@ -4,9 +4,9 @@ import ( "encoding/base64" "net/http" "net/url" + "slices" "strings" - "github.com/codeshelldev/secured-signal-api/utils" log "github.com/codeshelldev/secured-signal-api/utils/logger" ) @@ -36,7 +36,7 @@ func getAuthType(str string) authType { } func isValidToken(tokens []string, match string) (bool) { - return utils.Contains(tokens, match) + return slices.Contains(tokens, match) } func (data AuthMiddleware) Use() http.Handler { diff --git a/utils/utils.go b/utils/utils.go index 3ea28ff..67368ff 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -30,16 +30,6 @@ func StringToArray(sliceStr string) ([]string, error) { return tokens, nil } -func Contains[T comparable](list []T, item T) (bool){ - for _, match := range list { - if match == item { - return true - } - } - - return false -} - func GetJsonSafe[T any](jsonStr string) (T, error) { var result T From 29e07b2aa8be7bcb72828560802c02729bba5857 Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:23:13 +0200 Subject: [PATCH 07/13] add if check before assigning to ENV --- utils/env/env.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/utils/env/env.go b/utils/env/env.go index 01ba931..db14bf4 100644 --- a/utils/env/env.go +++ b/utils/env/env.go @@ -101,9 +101,19 @@ func Load() { ENV.API_TOKENS = apiTokens } - ENV.BLOCKED_ENDPOINTS = utils.GetJson[[]string](blockedEndpointJSON) - ENV.MESSAGE_ALIASES = utils.GetJson[[]middlewares.MessageAlias](messageAliasesJSON) + if blockedEndpointJSON != "" { + ENV.BLOCKED_ENDPOINTS = utils.GetJson[[]string](blockedEndpointJSON) + } + + if messageAliasesJSON != "" { + ENV.MESSAGE_ALIASES = utils.GetJson[[]middlewares.MessageAlias](messageAliasesJSON) + } - ENV.VARIABLES = utils.GetJson[map[string]any](variablesJSON) - ENV.VARIABLES["RECIPIENTS"] = utils.GetJson[[]string](recipientsJSON) + if variablesJSON != "" { + ENV.VARIABLES = utils.GetJson[map[string]any](variablesJSON) + } + + if recipientsJSON != "" { + ENV.VARIABLES["RECIPIENTS"] = utils.GetJson[[]string](recipientsJSON) + } } \ No newline at end of file From 167f55579e4fdc6b112174956aa93ec65366b7e1 Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:28:24 +0200 Subject: [PATCH 08/13] debugging --- utils/env/env.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/env/env.go b/utils/env/env.go index db14bf4..f116d71 100644 --- a/utils/env/env.go +++ b/utils/env/env.go @@ -2,6 +2,7 @@ package env import ( "os" + "strconv" middlewares "github.com/codeshelldev/secured-signal-api/internals/proxy/middlewares" "github.com/codeshelldev/secured-signal-api/utils" @@ -98,6 +99,8 @@ func Load() { ENV.BLOCKED_ENDPOINTS = []string{} } else { + log.Debug("Registered " + strconv.Itoa(len(apiTokens)) + " Tokens") + ENV.API_TOKENS = apiTokens } From 9112b6a52c903001443ed8eb0f36f0c472487051 Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:37:14 +0200 Subject: [PATCH 09/13] show 2 first chars of Token in debug mode --- utils/env/env.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/env/env.go b/utils/env/env.go index f116d71..1ae62f2 100644 --- a/utils/env/env.go +++ b/utils/env/env.go @@ -99,6 +99,10 @@ func Load() { ENV.BLOCKED_ENDPOINTS = []string{} } else { + for _, token := range apiTokens { + log.Debug("Found Token: " + token[:2] + strconv.Itoa(len(token))) + } + log.Debug("Registered " + strconv.Itoa(len(apiTokens)) + " Tokens") ENV.API_TOKENS = apiTokens From abd70d5f5518f711c21dbbcfcf4d47e5c30979d8 Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:38:59 +0200 Subject: [PATCH 10/13] added what I actually wanted to :) --- utils/env/env.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/env/env.go b/utils/env/env.go index 1ae62f2..8258551 100644 --- a/utils/env/env.go +++ b/utils/env/env.go @@ -3,6 +3,7 @@ package env import ( "os" "strconv" + "strings" middlewares "github.com/codeshelldev/secured-signal-api/internals/proxy/middlewares" "github.com/codeshelldev/secured-signal-api/utils" @@ -100,7 +101,7 @@ func Load() { ENV.BLOCKED_ENDPOINTS = []string{} } else { for _, token := range apiTokens { - log.Debug("Found Token: " + token[:2] + strconv.Itoa(len(token))) + log.Debug("Found Token: " + token[:2] + strings.Repeat("X", len(token))) } log.Debug("Registered " + strconv.Itoa(len(apiTokens)) + " Tokens") From 4751ddf30b3f6380d7e48f3139518ca4e669460b Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:40:16 +0200 Subject: [PATCH 11/13] remove 2 chars of "XXX" since it already shows the 2 chars --- utils/env/env.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/env/env.go b/utils/env/env.go index 8258551..a25d9ea 100644 --- a/utils/env/env.go +++ b/utils/env/env.go @@ -101,7 +101,7 @@ func Load() { ENV.BLOCKED_ENDPOINTS = []string{} } else { for _, token := range apiTokens { - log.Debug("Found Token: " + token[:2] + strings.Repeat("X", len(token))) + log.Debug("Found Token: " + token[:2] + strings.Repeat("X", len(token) - 2)) } log.Debug("Registered " + strconv.Itoa(len(apiTokens)) + " Tokens") From 2e502e3463f03fe1a323db08a77bc3069570f33e Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:53:12 +0200 Subject: [PATCH 12/13] more debugging --- internals/proxy/middlewares/auth.go | 6 ++++++ utils/logger/logger.go | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/internals/proxy/middlewares/auth.go b/internals/proxy/middlewares/auth.go index ba3417a..d8e2e02 100644 --- a/internals/proxy/middlewares/auth.go +++ b/internals/proxy/middlewares/auth.go @@ -36,6 +36,12 @@ func getAuthType(str string) authType { } func isValidToken(tokens []string, match string) (bool) { + for _, token := range tokens { + log.Debug("Checking Token: " + token[:2] + strings.Repeat("X", len(token) - 2)) + } + + log.Debug("Against: " + match[:2] + strings.Repeat("X", len(match) - 2)) + return slices.Contains(tokens, match) } diff --git a/utils/logger/logger.go b/utils/logger/logger.go index 40dc904..7847ec2 100644 --- a/utils/logger/logger.go +++ b/utils/logger/logger.go @@ -48,16 +48,16 @@ func Init(level string) { func getLogLevel(level string) zapcore.Level { switch level { - case "info": - return zapcore.InfoLevel - case "debug": - return zapcore.DebugLevel - case "warn": - return zapcore.WarnLevel - case "error": - return zapcore.ErrorLevel - default: - return zapcore.InfoLevel + case "info": + return zapcore.InfoLevel + case "debug": + return zapcore.DebugLevel + case "warn": + return zapcore.WarnLevel + case "error": + return zapcore.ErrorLevel + default: + return zapcore.InfoLevel } } From c2f02d40e820400d5b70cee70ec7ebfb6ba2467e Mon Sep 17 00:00:00 2001 From: CodeShell <122738806+CodeShellDev@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:57:46 +0200 Subject: [PATCH 13/13] removed temp. debug --- internals/proxy/middlewares/auth.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/internals/proxy/middlewares/auth.go b/internals/proxy/middlewares/auth.go index d8e2e02..ba3417a 100644 --- a/internals/proxy/middlewares/auth.go +++ b/internals/proxy/middlewares/auth.go @@ -36,12 +36,6 @@ func getAuthType(str string) authType { } func isValidToken(tokens []string, match string) (bool) { - for _, token := range tokens { - log.Debug("Checking Token: " + token[:2] + strings.Repeat("X", len(token) - 2)) - } - - log.Debug("Against: " + match[:2] + strings.Repeat("X", len(match) - 2)) - return slices.Contains(tokens, match) }