mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-11-04 08:05:42 +00:00 
			
		
		
		
	fix: validate resource file paths in ui middleware
This commit is contained in:
		@@ -4,6 +4,7 @@ import (
 | 
				
			|||||||
	"io/fs"
 | 
						"io/fs"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"tinyauth/internal/assets"
 | 
						"tinyauth/internal/assets"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -52,7 +53,15 @@ func (m *UIMiddleware) Middleware() gin.HandlerFunc {
 | 
				
			|||||||
			c.Next()
 | 
								c.Next()
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		case "resources":
 | 
							case "resources":
 | 
				
			||||||
			_, err := os.Stat(m.Config.ResourcesDir + strings.TrimPrefix(c.Request.URL.Path, "/resources/"))
 | 
								requestFilePath := m.Config.ResourcesDir + strings.TrimPrefix(c.Request.URL.Path, "/resources/")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if !filepath.IsLocal(requestFilePath) {
 | 
				
			||||||
 | 
									c.Status(404)
 | 
				
			||||||
 | 
									c.Abort()
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								_, err := os.Stat(requestFilePath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if os.IsNotExist(err) {
 | 
								if os.IsNotExist(err) {
 | 
				
			||||||
				c.Status(404)
 | 
									c.Status(404)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user