Class MaskingRequestLog

All Implemented Interfaces:
RequestLog, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle

public class MaskingRequestLog extends ContainerLifeCycle implements RequestLog
A request log that masks secrets before another request log writes the line (work order CC-PWA-V5F-APPURL-LEGACY, design CC-DESIGN-APP-URL-V2 section 3.2, decision AU-7): the VALUE of every query member named pw, password, prt, v, epw, hash or rt is replaced by ***, for every request - the legacy page, the page under /app/, the WebSocket upgrade and iiziRun's app.json alike. The names are the password members of the legacy URL, the password reset token and the e-mail verification token of SignIn, the Diffie-Hellman-encrypted password of iiziRun, VSViewer's hash, and the reconnect token of a WebSocket reconnection (CC-FIX-RECONNECT-TOKEN). The session ID of a reconnection (reconnect) is written in the masked form of every server log line (SessionID.maskID(String): its beginning and end with ... between), so that the request can be matched to the session's lines while the ID cannot be used to reconnect. Everything else of the line - the application, the language - is written as it came, which is why the log format keeps its query.

The query of the Referer header is masked the same way: a Browser sends the whole URL of the page as the Referer of every same-origin request the page makes, so a secret in the address bar would otherwise be logged once per resource of the page.

The wrapped log is a bean of this one: it is started and stopped with it, as the server starts and stops the request log it is given.

maskQuery(String) is the one masking helper of the server: every other line that writes a raw query to a log calls it.

Author:
Christopher Mindus
  • Field Details

  • Constructor Details

    • MaskingRequestLog

      public MaskingRequestLog(RequestLog log)
      Wraps a request log.
      Parameters:
      log - The request log that writes the line, never null.
  • Method Details

    • log

      public void log(Request request, Response response)
      Logs a request through the wrapped log, which sees the request with its secrets masked.
      Specified by:
      log in interface RequestLog
      Parameters:
      request - The request.
      response - The response.
    • maskQuery

      public static String maskQuery(String query)
      Masks the secrets of a raw query string: the value of every member named pw, password, prt, v, epw, hash or rt is replaced by MASK, and the value of a member named reconnect - a session ID - by its masked form (SessionID.maskID(String)). A name is compared decoded and without regard to case; a member without '=' has no value and is kept. Nothing else is changed: the members stay in their order, encoded as they came.
      Parameters:
      query - The query, without the question mark, null for none.
      Returns:
      The query to write to a log: the same string when it has nothing to mask, null for null.
    • maskURL

      public static String maskURL(String url)
      Masks the secrets of the query of a URL, as maskQuery(String) does: for the Referer header. The fragment, if any, is kept.
      Parameters:
      url - The URL, null for none.
      Returns:
      The URL to write to a log: the same string when it has nothing to mask, null for null.
    • isMaskedName

      public static boolean isMaskedName(String name)
      Tests whether the name of a query member is one whose value is masked: for a caller that holds the members apart and writes them to a log itself.
      Parameters:
      name - The name, encoded as it came or decoded.
      Returns:
      true when masked.