Skip to content

Commit

Permalink
fix: update user-agent regex to use regexp2 and handle match errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SunBK201 committed Nov 2, 2024
1 parent 3c85d70 commit fb0d56d
Show file tree
Hide file tree
Showing 55 changed files with 32 additions and 25 deletions.
22 changes: 11 additions & 11 deletions bin/sha1sum.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
63a160690ef8aaf5770c410ce8a421fd ./ua3f-0.5.0-386.tar.gz
4cd727205aa52fd3606b42b60e9e0593 ./ua3f-0.5.0-amd64.tar.gz
c4101e2605391754d52b38ceb8ceb1f5 ./ua3f-0.5.0-arm.tar.gz
392aa3e532973dc0f2b4f87691dd5572 ./ua3f-0.5.0-arm64.tar.gz
d5098bca9f040865d4076de2cc131e44 ./ua3f-0.5.0-armv7.tar.gz
392aa3e532973dc0f2b4f87691dd5572 ./ua3f-0.5.0-armv8.tar.gz
c0a6f242eff63595a8dc661de1e4390f ./ua3f-0.5.0-mips64.tar.gz
a6f7c49f5437d601077856d15b9ba8e7 ./ua3f-0.5.0-mipsle-hardfloat.tar.gz
6f966df9a8e5c74a81c3e75d1b06ad9d ./ua3f-0.5.0-mipsle-softfloat.tar.gz
3f8974026e09b59d95ee21ed0a9db4b6 ./ua3f-0.5.0-mipsle.tar.gz
c86d8d56781d9b5e94805ca76e232dda ./ua3f-0.5.0-riscv64.tar.gz
40758678c03ace553b3c4d5690218c52 ./ua3f-0.5.1-386.tar.gz
43b8ec1a2dd43c8e6d826b4f785fabc9 ./ua3f-0.5.1-amd64.tar.gz
1ea04bd958de26947ddaf7f272fb5aff ./ua3f-0.5.1-arm.tar.gz
5c87c290de8e40715bc8802d7c7f09d2 ./ua3f-0.5.1-arm64.tar.gz
3fec71215b595a069c5e6c438178e355 ./ua3f-0.5.1-armv7.tar.gz
5c87c290de8e40715bc8802d7c7f09d2 ./ua3f-0.5.1-armv8.tar.gz
c2b0a620f66c6140b9c64667d6015709 ./ua3f-0.5.1-mips64.tar.gz
d4e325e5d7ac0c64a8ef659d04ca3164 ./ua3f-0.5.1-mipsle-hardfloat.tar.gz
df1295c649a05d2b32ecc18700ca8489 ./ua3f-0.5.1-mipsle-softfloat.tar.gz
6528a2b69d3c67dc7606de15e293d06c ./ua3f-0.5.1-mipsle.tar.gz
3b064e7e7f4a18ca0b4750d7988b8d11 ./ua3f-0.5.1-riscv64.tar.gz
Binary file removed bin/ua3f-0.5.0-386.tar.gz
Binary file not shown.
Binary file removed bin/ua3f-0.5.0-amd64.tar.gz
Binary file not shown.
Binary file removed bin/ua3f-0.5.0-arm.tar.gz
Binary file not shown.
Binary file removed bin/ua3f-0.5.0-arm64.tar.gz
Binary file not shown.
Binary file removed bin/ua3f-0.5.0-armv7.tar.gz
Binary file not shown.
Binary file removed bin/ua3f-0.5.0-armv8.tar.gz
Binary file not shown.
Binary file removed bin/ua3f-0.5.0-mips64.tar.gz
Binary file not shown.
Binary file removed bin/ua3f-0.5.0-mipsle-hardfloat.tar.gz
Binary file not shown.
Binary file removed bin/ua3f-0.5.0-mipsle-softfloat.tar.gz
Binary file not shown.
Binary file removed bin/ua3f-0.5.0-mipsle.tar.gz
Binary file not shown.
Binary file removed bin/ua3f-0.5.0-riscv64.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-386.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-amd64.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-arm.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-arm64.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-armv7.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-armv8.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-mips64.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-mipsle-hardfloat.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-mipsle-softfloat.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-mipsle.tar.gz
Binary file not shown.
Binary file added bin/ua3f-0.5.1-riscv64.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

project_name="ua3f"
release_version="0.5.0"
release_version="0.5.1"
target=cmd/ua3f.go
dist=./dist
release_dir=./bin
Expand Down
14 changes: 9 additions & 5 deletions cmd/ua3f.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import (
"fmt"
"io"
"net"
"regexp"
"slices"
"strings"
"time"
"ua3f/http"
"ua3f/log"

"github.com/dlclark/regexp2"
"github.com/hashicorp/golang-lru/v2/expirable"
"github.com/sirupsen/logrus"
)

var version = "0.5.0"
var version = "0.5.1"
var payloadByte []byte
var uaPattern string
var uaRegexp *regexp.Regexp
var uaRegexp *regexp2.Regexp
var cache *expirable.LRU[string, string]
var HTTP_METHOD = []string{"GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS", "TRACE", "CONNECT"}
var whitelist = []string{
Expand Down Expand Up @@ -77,7 +77,7 @@ func main() {
return
}
logrus.Info(fmt.Sprintf("Listen on %s:%d", addr, port))
uaRegexp, err = regexp.Compile(uaPattern)
uaRegexp, err = regexp2.Compile(uaPattern, regexp2.None)
if err != nil {
logrus.Fatal("Invalid User-Agent Regex Pattern: ", err)
return
Expand Down Expand Up @@ -440,7 +440,11 @@ func CopyPileline(dst io.Writer, src io.Reader, destAddrPort string) {
isInWhiteList := false
isMatchUaPattern := true
if uaPattern != "" {
isMatchUaPattern = uaRegexp.MatchString(uaStr)
isMatchUaPattern, err = uaRegexp.MatchString(uaStr)
if err != nil {
logrus.Error(fmt.Sprintf("[%s][%s] User-Agent Regex Pattern Match Error: %s", destAddrPort, src.(*net.TCPConn).RemoteAddr().String(), err.Error()))
isMatchUaPattern = true
}
}
if slices.Contains(whitelist, uaStr) {
isInWhiteList = true
Expand Down
Binary file removed dist/ua3f_0.5.0-1_386.ipk
Binary file not shown.
Binary file removed dist/ua3f_0.5.0-1_amd64.ipk
Binary file not shown.
Binary file removed dist/ua3f_0.5.0-1_arm.ipk
Binary file not shown.
Binary file removed dist/ua3f_0.5.0-1_arm64.ipk
Binary file not shown.
Binary file removed dist/ua3f_0.5.0-1_armv7.ipk
Binary file not shown.
Binary file removed dist/ua3f_0.5.0-1_armv8.ipk
Binary file not shown.
Binary file removed dist/ua3f_0.5.0-1_mips64.ipk
Binary file not shown.
Binary file removed dist/ua3f_0.5.0-1_mipsle-hardfloat.ipk
Binary file not shown.
Binary file removed dist/ua3f_0.5.0-1_mipsle-softfloat.ipk
Binary file not shown.
Binary file removed dist/ua3f_0.5.0-1_mipsle.ipk
Binary file not shown.
Binary file removed dist/ua3f_0.5.0-1_riscv64.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_386.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_amd64.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_arm.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_arm64.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_armv7.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_armv8.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_mips64.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_mipsle-hardfloat.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_mipsle-softfloat.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_mipsle.ipk
Binary file not shown.
Binary file added dist/ua3f_0.5.1-1_riscv64.ipk
Binary file not shown.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
)

require (
github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/stretchr/testify v1.8.2 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
)
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -9,7 +11,7 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.1/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ckcmd() {
cd /root
getcpucore

version=0.5.0
version=0.5.1
ua3f_tar=ua3f-$version-$cpucore.tar.gz

if id -u shellclash >/dev/null 2>&1; then
Expand Down
2 changes: 1 addition & 1 deletion luci/cbi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local uci = require("luci.model.uci").cursor()
ua3f = Map("ua3f",
"UA3F",
[[
<a href="https://github.com/SunBK201/UA3F" target="_blank">Version: 0.5.0</a>
<a href="https://github.com/SunBK201/UA3F" target="_blank">Version: 0.5.1</a>
<br>
Across the Campus we can reach every corner in the world.
]]
Expand Down
4 changes: 2 additions & 2 deletions opkg/CONTROL/control
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: ua3f
Version: 0.5.0-1
Version: 0.5.1-1
Depends: libc, luci-compat
Source: /feed/openwrt
SourceName: UA3F
License: GPL-3.0-only
Section: net
SourceDateEpoch: 1711267200
Architecture: all
Installed-Size: 2641920
Installed-Size: 2775040
Description: Implementation of the new generation of HTTP User-Agent modification methodology.
4 changes: 2 additions & 2 deletions opkg/CONTROL/control-e
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: ua3f
Version: 0.5.0-1
Version: 0.5.1-1
Depends: libc, luci-compat
Source: /feed/openwrt
SourceName: UA3F
License: GPL-3.0-only
Section: net
SourceDateEpoch: 1711267200
Architecture: all
Installed-Size: 2641920
Installed-Size: 2703360
Description: Implementation of the new generation of HTTP User-Agent modification methodology.
Binary file modified opkg/usr/bin/ua3f
Binary file not shown.
2 changes: 1 addition & 1 deletion opkg/usr/lib/lua/luci/model/cbi/ua3f.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local uci = require("luci.model.uci").cursor()
ua3f = Map("ua3f",
"UA3F",
[[
<a href="https://github.com/SunBK201/UA3F" target="_blank">Version: 0.5.0</a>
<a href="https://github.com/SunBK201/UA3F" target="_blank">Version: 0.5.1</a>
<br>
Across the Campus we can reach every corner in the world.
]]
Expand Down

0 comments on commit fb0d56d

Please sign in to comment.