-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filter password query parameter in access log (#919)
* filter password query parameter in access log * compile the regex * Added more test cases * should replace password no matter the occurance * should filter apikey no matter the occurance in the url string * undo unintentional commits Co-authored-by: Ed Shryane <eshryane@ripe.net>
- Loading branch information
Showing
3 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
whois-api/src/main/java/net/ripe/db/whois/api/httpserver/FilteredSlf4jRequestLogWriter.java
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,30 @@ | ||
package net.ripe.db.whois.api.httpserver; | ||
|
||
import org.eclipse.jetty.server.Slf4jRequestLogWriter; | ||
|
||
import java.io.IOException; | ||
import java.util.regex.Pattern; | ||
|
||
public class FilteredSlf4jRequestLogWriter extends Slf4jRequestLogWriter { | ||
private final String keyToFilter; | ||
// Replace value passed to apikey with "FILTERED" but leave the last 3 characters if its API keys | ||
private static final Pattern ApiKeyPattern = Pattern.compile("(?<=(?i)(apikey=))(.+?(?=\\S{3}[&|\\s]))"); | ||
private static final Pattern PasswordPattern = Pattern.compile("(?<=(?i)(password=))([^&]*)"); | ||
|
||
public FilteredSlf4jRequestLogWriter(String keyToFilter) { | ||
this.keyToFilter = keyToFilter; | ||
} | ||
|
||
@Override | ||
public void write(String requestEntry) throws IOException { | ||
String filtered; | ||
|
||
if (keyToFilter != null && keyToFilter.equalsIgnoreCase("apikey")) { | ||
filtered = ApiKeyPattern.matcher(requestEntry).replaceAll("FILTERED"); | ||
} else { | ||
filtered = PasswordPattern.matcher(requestEntry).replaceAll("FILTERED"); | ||
} | ||
|
||
super.write(filtered); | ||
} | ||
} |
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