I'm working on an application that sends some sensitive information as plain text via the URL query string. My goal is to customize my jetty requestlog so that any sensitive information is redacted or removed before being logged.
So far I've tried making a custom filter which did remove sensitive information from the query string but when I kept the native jetty logging enabled I was getting double logs (one with password and one without) and when I disabled the native logging I wasn't getting invalid traffic (requests that come to the correct service but have some other issue with the query string).
My question is, is there a way to either keep using my filter and not have jetty log a duplicate entry with the same information or is there a different method to clean up passwords (How can I implement a different logger, modify jetty requestlog jar?). I'm almost brand new to the world of development so I have no idea what's possible.
filter for reference
@Component
@Order(1)
public class RequestLogFilter implements Filter {
private final static Logger log = LogManager.getLogger(RequestLogFilter.class);
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) servletRequest;
String uriPath = req.getRequestURI();
String uri = req.getQueryString();
uri = uri != null ? uri.replaceAll("password.+?&", "password=redacted&") : "";
String method = req.getMethod();
String ip = req.getRemoteAddr();
String protocol = req.getProtocol();
String logString = ip + " - - " + '"' + method + " " + uriPath + "?" + uri + " " + protocol + '"';
log.info(logString);
filterChain.doFilter(servletRequest, servletResponse);
}
@Override
public void destroy() {
log.warn("Destructing RequestLogFilter :{}");
}
}