改进静态文件目录安全访问控制

This commit is contained in:
John
2018-04-23 14:20:41 +08:00
parent bd140dcba6
commit 721c1091d0
5 changed files with 17 additions and 9 deletions

View File

@ -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、对于新增加的模块同时也增加了对应的开发文档并梳理完善了现有的其他模块开发文档

View File

@ -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)

View File

@ -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()

View File

@ -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()
}

View File

@ -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) )
}