Skip to content

Commit

Permalink
Fixed token leaks (#1364)
Browse files Browse the repository at this point in the history
* Fixed token leaks

* generalized masking tokens
  • Loading branch information
itsKedar authored Jul 26, 2024
1 parent 1d9fefa commit 8d74139
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ private String getFileUrl(ScanRequest request, String filename) {
return null;
}
String repoUrl = request.getRepoUrl().replace(".git", "/");
if ( !ScanUtils.empty(repoUrl) && repoUrl.contains("gitlab-ci-token") && repoUrl.contains("@")) {
repoUrl = repoUrl.substring(0, 8) + repoUrl.substring(repoUrl.indexOf('@') + 1);
}
return (Optional.ofNullable(filename).isPresent())
? String.format(String.format("%s/blob/%%s/%%s", repoUrl), request.getBranch(), filename)
: null;
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
<maskPattern>"access_token":"([^"]+)"</maskPattern>
<maskPattern>Authorization: Bearer (.+)</maskPattern>
<!-- Mask GitHub tokens -->
<maskPattern>https://([_a-zA-Z0-9]+)@github.com</maskPattern>
<maskPattern>Authorization: token ([_a-zA-Z0-9]+)$</maskPattern>
<maskPattern>https://([_a-zA-Z0-9:.\\-]+|)@.+</maskPattern>
<maskPattern>Authorization: token ([_a-zA-Z0-9]+)$</maskPattern>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</layout>
</encoder>
Expand Down Expand Up @@ -90,8 +90,8 @@
<maskPattern>"access_token":"([^"]+)"</maskPattern>
<maskPattern>Authorization: Bearer (.+)</maskPattern>
<!-- Mask GitHub tokens -->
<maskPattern>https://([_a-zA-Z0-9]+)@github.com</maskPattern>
<maskPattern>Authorization: token ([_a-zA-Z0-9]+)$</maskPattern>
<maskPattern>https://([_a-zA-Z0-9:.\\-]+|)@.+</maskPattern>
<maskPattern>Authorization: token ([_a-zA-Z0-9]+)$</maskPattern>
<pattern>${FILE_LOG_PATTERN}</pattern>
</layout>
</encoder>
Expand Down

0 comments on commit 8d74139

Please sign in to comment.