-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add sqlInjectSafe; add respUsersFavoriteCountMap
- Loading branch information
derekwin
committed
Feb 21, 2023
1 parent
ab3a3c8
commit 77fac74
Showing
7 changed files
with
108 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package safe | ||
|
||
import ( | ||
"errors" | ||
"regexp" | ||
) | ||
|
||
// ref: https://blog.csdn.net/qq_40127376/article/details/108516561 | ||
var sqlInjectReg = regexp.MustCompile(`(.*\=.*\-\-.*)|(.*(\+|\-).*)|(.*\w+(%|\$|#|&)\w+.*)|(.*\|\|.*)|(.*\s+(and|or)\s+.*)|(.*\b(select|update|union|and|or|delete|insert|trancate|char|into|substr|ascii|declare|exec|count|master|into|drop|execute)\b.*)`) | ||
|
||
func SqlInjectCheck(input string) error { | ||
reg := sqlInjectReg.FindAllString(input, 1) // 匹配一个就行 | ||
if reg != nil { | ||
return errors.New("输入存在非法字段") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package safe | ||
|
||
import ( | ||
"log" | ||
"testing" | ||
) | ||
|
||
func TestSqlInjectCheck(t *testing.T) { | ||
str1 := "select 1" | ||
err := SqlInjectCheck(str1) | ||
if err != nil { | ||
log.Println(err) | ||
return | ||
} | ||
log.Println("no") | ||
} |