Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
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
GitHub Mirror
Renovate Bot
renovate
Commits
69c9c98c
Unverified
Commit
69c9c98c
authored
3 years ago
by
Rhys Arkins
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: sanitize base64 of all secrets (#14423)
parent
1151f08d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/util/sanitize.spec.ts
+7
-0
7 additions, 0 deletions
lib/util/sanitize.spec.ts
lib/util/sanitize.ts
+14
-1
14 additions, 1 deletion
lib/util/sanitize.ts
with
21 additions
and
1 deletion
lib/util/sanitize.spec.ts
+
7
−
0
View file @
69c9c98c
...
@@ -11,6 +11,7 @@ describe('util/sanitize', () => {
...
@@ -11,6 +11,7 @@ describe('util/sanitize', () => {
});
});
it
(
'
sanitizes empty string
'
,
()
=>
{
it
(
'
sanitizes empty string
'
,
()
=>
{
addSecretForSanitizing
(
''
);
expect
(
sanitize
(
null
as
never
)).
toBeNull
();
expect
(
sanitize
(
null
as
never
)).
toBeNull
();
expect
(
sanitize
(
''
)).
toBe
(
''
);
expect
(
sanitize
(
''
)).
toBe
(
''
);
});
});
...
@@ -32,4 +33,10 @@ describe('util/sanitize', () => {
...
@@ -32,4 +33,10 @@ describe('util/sanitize', () => {
const
outputX2
=
[
output
,
output
].
join
(
'
\n
'
);
const
outputX2
=
[
output
,
output
].
join
(
'
\n
'
);
expect
(
sanitize
(
inputX2
)).
toBe
(
outputX2
);
expect
(
sanitize
(
inputX2
)).
toBe
(
outputX2
);
});
});
it
(
'
sanitizes github app tokens
'
,
()
=>
{
addSecretForSanitizing
(
'
x-access-token:abc123
'
);
expect
(
sanitize
(
`hello
${
toBase64
(
'
abc123
'
)}
world`
)).
toBe
(
'
hello **redacted** world
'
);
});
});
});
This diff is collapsed.
Click to expand it.
lib/util/sanitize.ts
+
14
−
1
View file @
69c9c98c
import
is
from
'
@sindresorhus/is
'
;
import
{
toBase64
}
from
'
./string
'
;
const
secrets
=
new
Set
<
string
>
();
const
secrets
=
new
Set
<
string
>
();
export
const
redactedFields
=
[
export
const
redactedFields
=
[
...
@@ -26,9 +29,19 @@ export function sanitize(input: string): string {
...
@@ -26,9 +29,19 @@ export function sanitize(input: string): string {
return
output
;
return
output
;
}
}
const
GITHUB_APP_TOKEN_PREFIX
=
'
x-access-token:
'
;
export
function
addSecretForSanitizing
(
secret
:
string
):
void
{
export
function
addSecretForSanitizing
(
secret
:
string
):
void
{
if
(
!
is
.
nonEmptyString
(
secret
))
{
return
;
}
secrets
.
add
(
secret
);
secrets
.
add
(
secret
);
secrets
.
add
(
secret
?.
replace
(
'
x-access-token:
'
,
''
));
// GitHub App tokens
secrets
.
add
(
toBase64
(
secret
));
if
(
secret
.
startsWith
(
GITHUB_APP_TOKEN_PREFIX
))
{
const
trimmedSecret
=
secret
.
replace
(
GITHUB_APP_TOKEN_PREFIX
,
''
);
secrets
.
add
(
trimmedSecret
);
secrets
.
add
(
toBase64
(
trimmedSecret
));
}
}
}
export
function
clearSanitizedSecretsList
():
void
{
export
function
clearSanitizedSecretsList
():
void
{
...
...
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