Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
510c202c
Commit
510c202c
authored
3 weeks ago
by
Leo du Plooy
Browse files
Options
Downloads
Patches
Plain Diff
Mask credit card details that is being sent to Raygun in the body of an api request.
parent
0da918e6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!61
Mask credit card details that is being sent to Raygun in the body of an api request.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
logs/logs.go
+9
-1
9 additions, 1 deletion
logs/logs.go
with
9 additions
and
1 deletion
logs/logs.go
+
9
−
1
View file @
510c202c
...
...
@@ -51,6 +51,7 @@ var raygunClient *raygun4go.Client
// Password filtering
var
passwordRegex
=
regexp
.
MustCompile
(
`(?i:\\?"password\\?"\s*:\s*\\?"(.*)\\?").*`
)
var
byteArrayRegex
=
regexp
.
MustCompile
(
`(?i:\\?"(?i:[\w]*)(?i:byte|data)(?i:[\w]*)\\?"\s*:\s*\[([\d\s,]+)*\])`
)
var
creditCardDetailsRegex
=
regexp
.
MustCompile
(
`(?i)"(?:card_number|card_expiry_year|card_expiry_month|card_cvv)"\s*:\s*(?:")?([^,"}]+)(?:")?`
)
func
SanitiseLogs
(
logString
string
)
string
{
var
isValidJsonString
bool
...
...
@@ -61,6 +62,7 @@ func SanitiseLogs(logString string) string {
logString
=
MaskByteArraysInJsonString
(
logString
)
logString
=
MaskPasswordsInJsonString
(
logString
)
logString
=
MaskCreditCardDetailsInJsonString
(
logString
)
return
logString
}
...
...
@@ -77,6 +79,12 @@ func MaskByteArraysInJsonString(jsonString string) string {
return
string_utils
.
ReplaceAllRegexStringSubmatch
(
byteArrayRegex
,
jsonString
,
"..."
)
}
// MaskCreditCardDetailsInJsonString takes a string and sanitises all the instances of fields named card_number,
// "card_number" will become "{"card_number": "***"}"
func
MaskCreditCardDetailsInJsonString
(
jsonString
string
)
string
{
return
string_utils
.
ReplaceAllRegexStringSubmatch
(
creditCardDetailsRegex
,
jsonString
,
"***"
)
}
func
SanitiseFields
(
fields
map
[
string
]
interface
{})
map
[
string
]
interface
{}
{
sanitisedFields
:=
make
(
map
[
string
]
interface
{})
...
...
@@ -491,7 +499,7 @@ func sendRaygunError(fields map[string]interface{}, errToSend error) {
if
apiRequest
!=
nil
{
methodAndPath
:=
apiRequest
.
HTTPMethod
+
": "
+
apiRequest
.
Path
tags
=
append
(
tags
,
methodAndPath
)
fields
[
"body"
]
=
apiRequest
.
Body
fields
[
"body"
]
=
SanitiseLogs
(
apiRequest
.
Body
)
fields
[
"query"
]
=
apiRequest
.
QueryStringParameters
fields
[
"identity"
]
=
apiRequest
.
RequestContext
.
Identity
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment