Compare commits

...

7 Commits

Author SHA1 Message Date
刘祥超
7763f26249 修复WAF的临时白名单被当做黑名单使用的Bug 2021-11-26 10:39:04 +08:00
刘祥超
b7ae10e2d0 修复合并URL中多余分隔符时导致参数发生变化的Bug 2021-11-24 15:01:06 +08:00
刘祥超
e54eddc961 服务增加是否合并URL中的多余分隔符选项 2021-11-24 14:50:07 +08:00
刘祥超
93db9d4926 版本号改为0.3.6 2021-11-24 14:04:01 +08:00
刘祥超
8c1af3e699 修复ipset无法提前删除IP的Bug 2021-11-24 10:21:02 +08:00
刘祥超
53c74553bc 修复ipset无法提前删除IP的Bug 2021-11-24 10:20:06 +08:00
刘祥超
3eb9cade0e 修改版本为0.3.5.2 2021-11-24 10:19:36 +08:00
7 changed files with 63 additions and 28 deletions

View File

@@ -1,7 +1,7 @@
package teaconst
const (
Version = "0.3.5"
Version = "0.3.6"
ProductName = "Edge Node"
ProcessName = "edge-node"

View File

@@ -297,10 +297,13 @@ func (this *IPSetAction) runActionSingleIP(action string, listType IPListType, i
case "deleteItem":
args = append(args, "del")
}
args = append(args, listName, item.IpFrom)
timestamp := time.Now().Unix()
if item.ExpiredAt > timestamp {
args = append(args, "timeout", strconv.FormatInt(item.ExpiredAt-timestamp, 10))
if action == "addItem" {
timestamp := time.Now().Unix()
if item.ExpiredAt > timestamp {
args = append(args, "timeout", strconv.FormatInt(item.ExpiredAt-timestamp, 10))
}
}
if runtime.GOOS == "darwin" {

View File

@@ -86,13 +86,21 @@ type HTTPRequest struct {
// 初始化
func (this *HTTPRequest) init() {
this.writer = NewHTTPWriter(this, this.RawWriter)
this.web = &serverconfigs.HTTPWebConfig{IsOn: true}
this.web = &serverconfigs.HTTPWebConfig{
IsOn: true,
}
// this.uri = this.RawReq.URL.RequestURI()
// 之所以不使用RequestURI()是不想让URL中的Path被Encode
var urlPath = this.RawReq.URL.Path
if this.Server.Web != nil && this.Server.Web.MergeSlashes {
urlPath = utils.CleanPath(urlPath)
this.web.MergeSlashes = true
}
if len(this.RawReq.URL.RawQuery) > 0 {
this.uri = this.RawReq.URL.Path + "?" + this.RawReq.URL.RawQuery
this.uri = urlPath + "?" + this.RawReq.URL.RawQuery
} else {
this.uri = this.RawReq.URL.Path
this.uri = urlPath
}
this.rawURI = this.uri

View File

@@ -1,6 +1,7 @@
package nodes
import (
"github.com/TeaOSLab/EdgeNode/internal/utils"
"net/http"
"strconv"
"strings"
@@ -8,7 +9,11 @@ import (
// 主机地址快速跳转
func (this *HTTPRequest) doHostRedirect() (blocked bool) {
fullURL := this.requestScheme() + "://" + this.Host + this.RawReq.URL.Path
var urlPath = this.RawReq.URL.Path
if this.web.MergeSlashes {
urlPath = utils.CleanPath(urlPath)
}
fullURL := this.requestScheme() + "://" + this.Host + urlPath
for _, u := range this.web.HostRedirects {
if !u.IsOn {
continue

View File

@@ -1,6 +1,6 @@
package utils
// 清理Path中的多余的字符
// CleanPath 清理Path中的多余的字符
func CleanPath(path string) string {
l := len(path)
if l == 0 {
@@ -9,6 +9,10 @@ func CleanPath(path string) string {
result := []byte{'/'}
isSlash := true
for i := 0; i < l; i++ {
if path[i] == '?' {
result = append(result, path[i:]...)
break
}
if path[i] == '\\' || path[i] == '/' {
if !isSlash {
isSlash = true
@@ -21,4 +25,3 @@ func CleanPath(path string) string {
}
return string(result)
}

View File

@@ -16,6 +16,11 @@ func TestCleanPath(t *testing.T) {
a.IsTrue(CleanPath("/hello////world") == "/hello/world")
}
func TestCleanPath_Args(t *testing.T) {
a := assert.NewAssertion(t)
a.IsTrue(CleanPath("/hello/world?base=///////") == "/hello/world?base=///////")
}
func BenchmarkCleanPath(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = CleanPath("/hello///world/very/long/very//long")

View File

@@ -10,8 +10,15 @@ import (
"sync/atomic"
)
var SharedIPWhiteList = NewIPList()
var SharedIPBlackList = NewIPList()
var SharedIPWhiteList = NewIPList(IPListTypeAllow)
var SharedIPBlackList = NewIPList(IPListTypeDeny)
type IPListType = string
const (
IPListTypeAllow IPListType = "allow"
IPListTypeDeny IPListType = "deny"
)
const IPTypeAll = "*"
@@ -20,16 +27,18 @@ type IPList struct {
expireList *expires.List
ipMap map[string]int64 // ip => id
idMap map[int64]string // id => ip
listType IPListType
id int64
locker sync.RWMutex
}
// NewIPList 获取新对象
func NewIPList() *IPList {
func NewIPList(listType IPListType) *IPList {
var list = &IPList{
ipMap: map[string]int64{},
idMap: map[int64]string{},
ipMap: map[string]int64{},
idMap: map[int64]string{},
listType: listType,
}
e := expires.NewList()
@@ -67,20 +76,22 @@ func (this *IPList) Add(ipType string, scope firewallconfigs.FirewallScope, serv
func (this *IPList) RecordIP(ipType string, scope firewallconfigs.FirewallScope, serverId int64, ip string, expiresAt int64, policyId int64, groupId int64, setId int64) {
this.Add(ipType, scope, serverId, ip, expiresAt)
select {
case recordIPTaskChan <- &recordIPTask{
ip: ip,
listId: firewallconfigs.GlobalListId,
expiredAt: expiresAt,
level: firewallconfigs.DefaultEventLevel,
serverId: serverId,
sourceServerId: serverId,
sourceHTTPFirewallPolicyId: policyId,
sourceHTTPFirewallRuleGroupId: groupId,
sourceHTTPFirewallRuleSetId: setId,
}:
default:
if this.listType == IPListTypeDeny {
select {
case recordIPTaskChan <- &recordIPTask{
ip: ip,
listId: firewallconfigs.GlobalListId,
expiredAt: expiresAt,
level: firewallconfigs.DefaultEventLevel,
serverId: serverId,
sourceServerId: serverId,
sourceHTTPFirewallPolicyId: policyId,
sourceHTTPFirewallRuleGroupId: groupId,
sourceHTTPFirewallRuleSetId: setId,
}:
default:
}
}
}