Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3c21652e
authored
Jan 05, 2026
by
xiangsx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add regex pattern to mask API keys in sensitive information
parent
04ff3df5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
0 deletions
+5
-0
common/str.go
+5
-0
No files found.
common/str.go
View file @
3c21652e
...
@@ -16,6 +16,8 @@ var (
...
@@ -16,6 +16,8 @@ var (
maskURLPattern
=
regexp
.
MustCompile
(
`(http|https)://[^\s/$.?#].[^\s]*`
)
maskURLPattern
=
regexp
.
MustCompile
(
`(http|https)://[^\s/$.?#].[^\s]*`
)
maskDomainPattern
=
regexp
.
MustCompile
(
`\b(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}\b`
)
maskDomainPattern
=
regexp
.
MustCompile
(
`\b(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}\b`
)
maskIPPattern
=
regexp
.
MustCompile
(
`\b(?:\d{1,3}\.){3}\d{1,3}\b`
)
maskIPPattern
=
regexp
.
MustCompile
(
`\b(?:\d{1,3}\.){3}\d{1,3}\b`
)
// maskApiKeyPattern matches patterns like 'api_key:xxx' or "api_key:xxx" to mask the API key value
maskApiKeyPattern
=
regexp
.
MustCompile
(
`(['"]?)api_key:([^\s'"]+)(['"]?)`
)
)
)
func
GetStringIfEmpty
(
str
string
,
defaultValue
string
)
string
{
func
GetStringIfEmpty
(
str
string
,
defaultValue
string
)
string
{
...
@@ -235,5 +237,8 @@ func MaskSensitiveInfo(str string) string {
...
@@ -235,5 +237,8 @@ func MaskSensitiveInfo(str string) string {
// Mask IP addresses
// Mask IP addresses
str
=
maskIPPattern
.
ReplaceAllString
(
str
,
"***.***.***.***"
)
str
=
maskIPPattern
.
ReplaceAllString
(
str
,
"***.***.***.***"
)
// Mask API keys (e.g., "api_key:AIzaSyAAAaUooTUni8AdaOkSRMda30n_Q4vrV70" -> "api_key:***")
str
=
maskApiKeyPattern
.
ReplaceAllString
(
str
,
"${1}api_key:***${3}"
)
return
str
return
str
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment