This is an automated email from the ASF dual-hosted git repository.
hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-mcp-gateway.git
The following commit(s) were added to refs/heads/master by this push:
new 3195b4e fix: only treat /login and /health as public paths
3195b4e is described below
commit 3195b4ef84a0ea20b130ed0907491a19861a581e
Author: Yang Luo <[email protected]>
AuthorDate: Sat Oct 10 01:11:09 2026 +0800
fix: only treat /login and /health as public paths
---
middleware/oauth.go | 27 +--------------------------
middleware/oauth_test.go | 12 +++++++-----
2 files changed, 8 insertions(+), 31 deletions(-)
diff --git a/middleware/oauth.go b/middleware/oauth.go
index c0e7d8f..64b14b1 100644
--- a/middleware/oauth.go
+++ b/middleware/oauth.go
@@ -68,30 +68,5 @@ func OAuth() beego.FilterFunc {
// isPublicPath checks if the path should skip authentication
func isPublicPath(path string) bool {
- publicPaths := []string{
- "/login",
- "/health",
- "/static/",
- "/favicon.ico",
- }
-
- // Check for exact matches or prefixes
- for _, publicPath := range publicPaths {
- if path == publicPath || strings.HasPrefix(path, publicPath) {
- return true
- }
- }
-
- // Allow static file extensions
- if strings.HasSuffix(path, ".html") ||
- strings.HasSuffix(path, ".css") ||
- strings.HasSuffix(path, ".js") ||
- strings.HasSuffix(path, ".png") ||
- strings.HasSuffix(path, ".jpg") ||
- strings.HasSuffix(path, ".ico") ||
- strings.HasSuffix(path, ".svg") {
- return true
- }
-
- return false
+ return path == "/login" || path == "/health"
}
diff --git a/middleware/oauth_test.go b/middleware/oauth_test.go
index 2e7d6bd..254523c 100644
--- a/middleware/oauth_test.go
+++ b/middleware/oauth_test.go
@@ -87,12 +87,14 @@ func TestPublicPaths(t *testing.T) {
}{
{"/login", true},
{"/health", true},
- {"/static/css/app.css", true},
- {"/favicon.ico", true},
- {"/index.html", true},
- {"/app.css", true},
- {"/app.js", true},
+ {"/static/css/app.css", false},
+ {"/favicon.ico", false},
+ {"/index.html", false},
+ {"/app.css", false},
+ {"/app.js", false},
+ {"/loginX", false},
{"/api/users", false},
+ {"/api/users/x.js", false},
{"/api/profile", false},
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]