mirror of
https://github.com/iflytek/skillhub.git
synced 2026-08-27 11:14:59 +00:00
fix(auth): omit account merge request bodies from logs
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
This commit is contained in:
parent
c6b18c6be6
commit
51d781908d
2 changed files with 41 additions and 1 deletions
|
|
@ -37,7 +37,8 @@ public class RequestLoggingFilter extends OncePerRequestFilter {
|
|||
"/sse"
|
||||
);
|
||||
private static final Set<String> SENSITIVE_BODY_PREFIXES = Set.of(
|
||||
"/api/v1/auth/"
|
||||
"/api/v1/auth/",
|
||||
"/api/v1/account/merge"
|
||||
);
|
||||
private final SensitiveLogSanitizer sensitiveLogSanitizer;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import java.util.List;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
|
@ -204,6 +206,43 @@ class RequestLoggingFilterTest {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"/api/v1/account/merge/reauthenticate/local",
|
||||
"/api/v1/account/merge/intents/merge-intent/secondary-auth/local",
|
||||
"/api/v1/account/merge/verify"
|
||||
})
|
||||
void doFilterInternal_omitsAccountMergeBody(String requestUri)
|
||||
throws Exception {
|
||||
RequestLoggingFilter filter = filter();
|
||||
attachAppender();
|
||||
MockHttpServletRequest request =
|
||||
new MockHttpServletRequest("POST", requestUri);
|
||||
request.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
request.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
request.setContent(
|
||||
"""
|
||||
{"username":"secondary-user","password":"body-secret",
|
||||
"verificationToken":"verification-secret"}
|
||||
""".getBytes(StandardCharsets.UTF_8));
|
||||
MockHttpServletResponse response =
|
||||
new MockHttpServletResponse();
|
||||
|
||||
filter.doFilter(
|
||||
request,
|
||||
response,
|
||||
(req, res) -> req.getReader().lines().count());
|
||||
|
||||
assertThat(loggedMessages()).anySatisfy(message -> {
|
||||
assertThat(message)
|
||||
.contains("POST " + requestUri)
|
||||
.doesNotContain("secondary-user")
|
||||
.doesNotContain("body-secret")
|
||||
.doesNotContain("verification-secret")
|
||||
.doesNotContain("Body:");
|
||||
});
|
||||
}
|
||||
|
||||
private RequestLoggingFilter filter() {
|
||||
return new RequestLoggingFilter(
|
||||
new SensitiveLogSanitizer());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue