private static void sanitizeMobileSearchKeys()

in ingestion-beam/src/main/java/com/mozilla/telemetry/decoder/MessageScrubber.java [542:575]


  private static void sanitizeMobileSearchKeys(ObjectNode searchNode) {
    Lists.newArrayList(searchNode.fieldNames()).forEach(name -> {
      Matcher match = MOBILE_SEARCH_CONTENT_PATTERN.matcher(name);
      if (match.matches()) {
        String prefix = match.group("prefix");
        String code = match.group("code");
        String channel = match.group("channel");
        boolean codeIsValid = ALLOWED_MOBILE_SEARCH_CODES.contains(code);
        boolean channelIsValid = Strings.isNullOrEmpty(channel)
            || ALLOWED_SEARCH_CHANNELS.contains(channel);
        if (codeIsValid && channelIsValid) {
          // Key is valid, so no rewrite is needed and we can return early.
          return;
        }

        // Sanitize the code and channel as needed.
        String newKey;
        if (codeIsValid) {
          newKey = prefix + code;
          if (ALLOWED_SEARCH_CHANNELS.contains(channel)) {
            // Channel is an optional field; we include it only if it's a known value.
            // See related client-side implementation in
            // https://github.com/mozilla-mobile/android-components/pull/11622
            newKey = String.format("%s.%s", newKey, channel);
          }
        } else {
          newKey = prefix + MOBILE_REDACTED_SEARCH_CODE_VALUE;
        }
        JsonNode value = searchNode.remove(name);
        searchNode.set(newKey, value);
        markBugCounter("1751955");
      }
    });
  }