feat(security): add validation for file path to prevent path traversal attacks

- Implemented a check to reject file paths containing "..", enhancing security against path traversal vulnerabilities in the file serving functionality.
main
wizardchen 2026-03-23 13:12:56 +08:00 committed by lyingbug
parent b2c009e61c
commit 39816f2756
1 changed files with 4 additions and 0 deletions

View File

@ -676,6 +676,10 @@ func serveFiles(r *gin.Engine) {
c.JSON(http.StatusBadRequest, gin.H{"error": "missing required parameter: file_path"})
return
}
if strings.Contains(filePath, "..") {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid file path"})
return
}
provider := types.ParseProviderScheme(filePath)