Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We changed to syntax for the websearch to the one of the main search bar. [#13607](https://github.com/JabRef/jabref/issues/13607)
- We improved the for the web search tab in the preferences dialog [#13791](https://github.com/JabRef/jabref/pull/13791)
- We improved the event viewer for debugging [#13783](https://github.com/JabRef/jabref/pull/13783).
- We improved "REDACTED" replacement of API key value in web fetcher search URL [#13796](https://github.com/JabRef/jabref/issues/13796)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

public class FetcherException extends JabRefException {
private static final Logger LOGGER = LoggerFactory.getLogger(FetcherException.class);
private static final Pattern API_KEY_PATTERN = Pattern.compile("(?i)(api|key|api[-_]?key)=[^&]*");
private static String REDACTED_STRING = "[REDACTED]";
private static final String API_KEY_PARAM_NAME = "apiKeyParamName";
private static final Pattern API_KEY_PATTERN = Pattern.compile("(?i)(?<" + API_KEY_PARAM_NAME + ">api|key|api[-_]?key)=[^&]*");
private static final String REDACTED_STRING = "[REDACTED]";

private final String url;
private final SimpleHttpResponse httpResponse;
Expand Down Expand Up @@ -85,12 +86,12 @@ public String getLocalizedMessage() {
}
}

private String getRedactedUrl() {
return API_KEY_PATTERN.matcher(url).replaceAll(REDACTED_STRING);
String getRedactedUrl() {
return getRedactedUrl(url);
}

public static Object getRedactedUrl(URL source) {
return API_KEY_PATTERN.matcher(source.toString()).replaceAll(REDACTED_STRING);
public static String getRedactedUrl(String source) {
return API_KEY_PATTERN.matcher(source).replaceAll("${" + API_KEY_PARAM_NAME + "}=" + REDACTED_STRING);
}

private String getPrefix() {
Expand Down
2 changes: 1 addition & 1 deletion jablib/src/main/java/org/jabref/logic/net/URLDownload.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public URLConnection openConnection() throws FetcherException {
} else if (status >= 400) {
// in case of an error, propagate the error message
SimpleHttpResponse httpResponse = new SimpleHttpResponse(httpURLConnection);
LOGGER.info("{}: {}", FetcherException.getRedactedUrl(this.source), httpResponse);
LOGGER.info("{}: {}", FetcherException.getRedactedUrl(this.source.toString()), httpResponse);
if (status < 500) {
throw new FetcherClientException(this.source, httpResponse);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jabref.logic.importer;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import static org.junit.jupiter.api.Assertions.assertEquals;

class FetcherExceptionTest {

@ParameterizedTest
@CsvSource({
"https://api.springernature.com/meta/v1/json?q=anything&api_key=abc&s=1&p=20, https://api.springernature.com/meta/v1/json?q=anything&api_key=[REDACTED]&s=1&p=20",
"https://api.springernature.com/meta/v1/json?q=anything&API_KEY=abc, https://api.springernature.com/meta/v1/json?q=anything&API_KEY=[REDACTED]",
"https://api.springernature.com/meta/v1/json?q=anything&apikey=abc123ABC, https://api.springernature.com/meta/v1/json?q=anything&apikey=[REDACTED]",
"https://api.springernature.com/meta/v1/json?q=anything, https://api.springernature.com/meta/v1/json?q=anything",
"https://api.springernature.com/meta/v1/json, https://api.springernature.com/meta/v1/json"
})
void getRedactedUrl(String url, String redactedUrl) {
assertEquals(redactedUrl, FetcherException.getRedactedUrl(url));
}
}
Loading