mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
改进静态文件目录安全访问控制
This commit is contained in:
2
RELEASE
2
RELEASE
@ -8,7 +8,7 @@
|
||||
7、 ghttp.Response去掉WriteString方法,统一使用Write方法返回数据流,是使用灵活的参数形式;
|
||||
8、 模板引擎增加模板变量暴露接口LockFunc/RLockFunc,以便支持开发者灵活处理模板变量;
|
||||
9、 ghttp.Server增加access & error log功能,并支持开发者自定义日志处理回调函数注册;
|
||||
10、 增加gredis包,支持对redis的客户端操作封装,并将gredis.Redis对象加入到gins单例管理器中进行统一配置管理维护;
|
||||
10、增加gredis包,支持对redis的客户端操作封装,并将gredis.Redis对象加入到gins单例管理器中进行统一配置管理维护;
|
||||
11、gins单例管理器增加对单例对象配置文件的自动检测更新机制,当配置文件在外部发生变更时,自动刷新单例管理器中的单例对象;
|
||||
12、gdb数据库ORM包增加And/Or条件链式方法,并改进Where/Data方法参数灵活性;
|
||||
13、对于新增加的模块,同时也增加了对应的开发文档,并梳理完善了现有的其他模块开发文档;
|
||||
|
||||
@ -16,7 +16,6 @@ import (
|
||||
"net/url"
|
||||
"net/http"
|
||||
"gitee.com/johng/gf/g/os/gfile"
|
||||
"gitee.com/johng/gf/g/util/gregx"
|
||||
"gitee.com/johng/gf/g/encoding/ghtml"
|
||||
)
|
||||
|
||||
@ -98,7 +97,7 @@ func (s *Server)serveFile(r *Request) {
|
||||
path = gfile.RealPath(path)
|
||||
if path != "" {
|
||||
// 文件/目录访问安全限制:服务的路径必须在ServerRoot下,否则会报错
|
||||
if gregx.IsMatchString("^" + s.config.ServerRoot, path) {
|
||||
if len(path) >= len(s.config.ServerRoot) && strings.EqualFold(path[0 : len(s.config.ServerRoot)], s.config.ServerRoot) {
|
||||
s.doServeFile(r, path)
|
||||
} else {
|
||||
r.Response.WriteStatus(http.StatusForbidden)
|
||||
|
||||
@ -57,8 +57,8 @@ func New(expire int, size...int) *Pool {
|
||||
expire : int32(expire),
|
||||
queue : glist.New(),
|
||||
funcs : glist.New(),
|
||||
freeEvents : make(chan struct{}, math.MaxUint32),
|
||||
funcEvents : make(chan struct{}, math.MaxUint32),
|
||||
freeEvents : make(chan struct{}, math.MaxInt32),
|
||||
funcEvents : make(chan struct{}, math.MaxInt32),
|
||||
stopEvents : make(chan struct{}, runtime.GOMAXPROCS(-1) + 1),
|
||||
}
|
||||
p.startWorkLoop()
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
package main
|
||||
|
||||
import "gitee.com/johng/gf/g/net/ghttp"
|
||||
import (
|
||||
"gitee.com/johng/gf/g/net/ghttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := ghttp.GetServer()
|
||||
s.SetIndexFolder(true)
|
||||
s.SetServerRoot("/home/www/")
|
||||
s.SetServerRoot("C:\\Documents and Settings\\Claymore\\桌面\\gf.test")
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
}
|
||||
|
||||
@ -2,9 +2,15 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitee.com/johng/gf/g/frame/gins"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(gins.Config().GetString("database.default.0.host"))
|
||||
s1 := `C:\Documents and Settings\Claymore\桌面\gf.test`
|
||||
s2 := `C:\Documents and Settings\Claymore\桌面\gf.tes`
|
||||
|
||||
|
||||
|
||||
|
||||
fmt.Println(len(s2) >= len(s1) && strings.EqualFold(s2[0 : len(s1)], s1) )
|
||||
}
|
||||
Reference in New Issue
Block a user