@Test public void testShouldScrubClientIdBug1489560() throws Exception { ObjectNode pingToBeScrubbed = Json.readObjectNode(("{\n" + " \"client_info\": {\n" + " \"client_id\": \"c0ffeec0-ffee-c0ff-eec0-ffeec0ffeec0\"" + " }}").getBytes(StandardCharsets.UTF_8)); Map<String, String> attributes = Maps.newHashMap( ImmutableMap.<String, String>builder().put(Attribute.DOCUMENT_NAMESPACE, "glean").build()); assertThrows(AffectedByBugException.class, () -> MessageScrubber.scrub(attributes, pingToBeScrubbed)); ObjectNode validPing = Json.readObjectNode(("{\n" + " \"client_info\": {\n" + " \"client_id\": null" + " }}").getBytes(StandardCharsets.UTF_8)); MessageScrubber.scrub(attributes, validPing); }
public static void scrub(Map<String, String> attributes, ObjectNode json) throws MessageShouldBeDroppedException, AffectedByBugException { final String namespace = attributes.get(Attribute.DOCUMENT_NAMESPACE); final String docType = attributes.get(Attribute.DOCUMENT_TYPE); final String appName = attributes.get(Attribute.APP_NAME); final String appVersion = attributes.get(Attribute.APP_VERSION); final String appUpdateChannel = attributes.get(Attribute.APP_UPDATE_CHANNEL); final String appBuildId = attributes.get(Attribute.APP_BUILD_ID); if (ParseUri.TELEMETRY.equals(namespace) && "crash".equals(docType) && "nightly".equals(appUpdateChannel) && "20190719094503".equals(appBuildId) && Optional.of(json) .map(j -> j.path("payload").path("metadata").path("MozCrashReason").textValue()) .filter(s -> s.contains("do not use eval with system privileges")) .isPresent()) { throw new MessageShouldBeDroppedException("1567596"); } if (ParseUri.TELEMETRY.equals(namespace) && "crash".equals(docType) && (("nightly".equals(appUpdateChannel) && (appVersion.startsWith("68") || appVersion.startsWith("69"))) || ("beta".equals(appUpdateChannel) && appVersion.startsWith("68"))) && Optional.of(json) .map(j -> j.path("payload").path("metadata").path("RemoteType").textValue()) .filter(s -> s.startsWith("webIsolated=")) .isPresent()) { throw new MessageShouldBeDroppedException("1562011"); } if (ParseUri.TELEMETRY.equals(namespace) && "bhr".equals(docType) && (appVersion.startsWith("68") || appVersion.startsWith("69")) && Optional.of(json) .map(j -> j.path("payload").path("hangs").elements()) .map(Streams::stream).orElseGet(Stream::empty).map(j -> j.path("remoteType")) .filter(JsonNode::isTextual) .anyMatch(j -> j.textValue().startsWith("webIsolated="))) { throw new MessageShouldBeDroppedException("1562011"); } if (IGNORED_NAMESPACES.containsKey(namespace)) { throw new UnwantedDataException(IGNORED_NAMESPACES.get(namespace)); } if (ParseUri.TELEMETRY.equals(namespace) && IGNORED_TELEMETRY_DOCTYPES.containsKey(docType)) { throw new UnwantedDataException(IGNORED_TELEMETRY_DOCTYPES.get(docType)); } if ("FirefoxOS".equals(appName)) { throw new UnwantedDataException("1618684"); } if (ParseUri.TELEMETRY.equals(namespace) && FIREFOX_ONLY_DOCTYPES.contains(docType) && !"Firefox".equals(appName)) { throw new UnwantedDataException("1592010"); } if (bug1489560Affected(attributes, json)) { throw new AffectedByBugException("1489560"); } if ("default-browser-agent".equals(namespace) && "1".equals(docType)) { throw new AffectedByBugException("1626020"); } if (bug1602844Affected(attributes)) { json.path("events").elements().forEachRemaining(event -> { JsonNode eventMapValues = event.path(5); if (eventMapValues.has("fxauid")) { ((ObjectNode) eventMapValues).replace("fxauid", NullNode.getInstance()); } markBugCounter("1602844"); }); } if (bug1162183Affected(attributes)) { JsonNode payload = json.path("payload"); if (payload.has("slowSQL")) { ((ObjectNode) payload).remove("slowSQL"); markBugCounter("1162183"); } } if (bug1642386Affected(attributes)) { json.path("payload").path("syncs").elements().forEachRemaining(syncItem -> { syncItem.path("engines").elements().forEachRemaining(engine -> { ((ObjectNode) engine).remove("outgoing"); markBugCounter("1642386"); }); }); } }
MessageScrubber { public static void scrub(Map<String, String> attributes, ObjectNode json) throws MessageShouldBeDroppedException, AffectedByBugException { final String namespace = attributes.get(Attribute.DOCUMENT_NAMESPACE); final String docType = attributes.get(Attribute.DOCUMENT_TYPE); final String appName = attributes.get(Attribute.APP_NAME); final String appVersion = attributes.get(Attribute.APP_VERSION); final String appUpdateChannel = attributes.get(Attribute.APP_UPDATE_CHANNEL); final String appBuildId = attributes.get(Attribute.APP_BUILD_ID); if (ParseUri.TELEMETRY.equals(namespace) && "crash".equals(docType) && "nightly".equals(appUpdateChannel) && "20190719094503".equals(appBuildId) && Optional.of(json) .map(j -> j.path("payload").path("metadata").path("MozCrashReason").textValue()) .filter(s -> s.contains("do not use eval with system privileges")) .isPresent()) { throw new MessageShouldBeDroppedException("1567596"); } if (ParseUri.TELEMETRY.equals(namespace) && "crash".equals(docType) && (("nightly".equals(appUpdateChannel) && (appVersion.startsWith("68") || appVersion.startsWith("69"))) || ("beta".equals(appUpdateChannel) && appVersion.startsWith("68"))) && Optional.of(json) .map(j -> j.path("payload").path("metadata").path("RemoteType").textValue()) .filter(s -> s.startsWith("webIsolated=")) .isPresent()) { throw new MessageShouldBeDroppedException("1562011"); } if (ParseUri.TELEMETRY.equals(namespace) && "bhr".equals(docType) && (appVersion.startsWith("68") || appVersion.startsWith("69")) && Optional.of(json) .map(j -> j.path("payload").path("hangs").elements()) .map(Streams::stream).orElseGet(Stream::empty).map(j -> j.path("remoteType")) .filter(JsonNode::isTextual) .anyMatch(j -> j.textValue().startsWith("webIsolated="))) { throw new MessageShouldBeDroppedException("1562011"); } if (IGNORED_NAMESPACES.containsKey(namespace)) { throw new UnwantedDataException(IGNORED_NAMESPACES.get(namespace)); } if (ParseUri.TELEMETRY.equals(namespace) && IGNORED_TELEMETRY_DOCTYPES.containsKey(docType)) { throw new UnwantedDataException(IGNORED_TELEMETRY_DOCTYPES.get(docType)); } if ("FirefoxOS".equals(appName)) { throw new UnwantedDataException("1618684"); } if (ParseUri.TELEMETRY.equals(namespace) && FIREFOX_ONLY_DOCTYPES.contains(docType) && !"Firefox".equals(appName)) { throw new UnwantedDataException("1592010"); } if (bug1489560Affected(attributes, json)) { throw new AffectedByBugException("1489560"); } if ("default-browser-agent".equals(namespace) && "1".equals(docType)) { throw new AffectedByBugException("1626020"); } if (bug1602844Affected(attributes)) { json.path("events").elements().forEachRemaining(event -> { JsonNode eventMapValues = event.path(5); if (eventMapValues.has("fxauid")) { ((ObjectNode) eventMapValues).replace("fxauid", NullNode.getInstance()); } markBugCounter("1602844"); }); } if (bug1162183Affected(attributes)) { JsonNode payload = json.path("payload"); if (payload.has("slowSQL")) { ((ObjectNode) payload).remove("slowSQL"); markBugCounter("1162183"); } } if (bug1642386Affected(attributes)) { json.path("payload").path("syncs").elements().forEachRemaining(syncItem -> { syncItem.path("engines").elements().forEachRemaining(engine -> { ((ObjectNode) engine).remove("outgoing"); markBugCounter("1642386"); }); }); } } }
MessageScrubber { public static void scrub(Map<String, String> attributes, ObjectNode json) throws MessageShouldBeDroppedException, AffectedByBugException { final String namespace = attributes.get(Attribute.DOCUMENT_NAMESPACE); final String docType = attributes.get(Attribute.DOCUMENT_TYPE); final String appName = attributes.get(Attribute.APP_NAME); final String appVersion = attributes.get(Attribute.APP_VERSION); final String appUpdateChannel = attributes.get(Attribute.APP_UPDATE_CHANNEL); final String appBuildId = attributes.get(Attribute.APP_BUILD_ID); if (ParseUri.TELEMETRY.equals(namespace) && "crash".equals(docType) && "nightly".equals(appUpdateChannel) && "20190719094503".equals(appBuildId) && Optional.of(json) .map(j -> j.path("payload").path("metadata").path("MozCrashReason").textValue()) .filter(s -> s.contains("do not use eval with system privileges")) .isPresent()) { throw new MessageShouldBeDroppedException("1567596"); } if (ParseUri.TELEMETRY.equals(namespace) && "crash".equals(docType) && (("nightly".equals(appUpdateChannel) && (appVersion.startsWith("68") || appVersion.startsWith("69"))) || ("beta".equals(appUpdateChannel) && appVersion.startsWith("68"))) && Optional.of(json) .map(j -> j.path("payload").path("metadata").path("RemoteType").textValue()) .filter(s -> s.startsWith("webIsolated=")) .isPresent()) { throw new MessageShouldBeDroppedException("1562011"); } if (ParseUri.TELEMETRY.equals(namespace) && "bhr".equals(docType) && (appVersion.startsWith("68") || appVersion.startsWith("69")) && Optional.of(json) .map(j -> j.path("payload").path("hangs").elements()) .map(Streams::stream).orElseGet(Stream::empty).map(j -> j.path("remoteType")) .filter(JsonNode::isTextual) .anyMatch(j -> j.textValue().startsWith("webIsolated="))) { throw new MessageShouldBeDroppedException("1562011"); } if (IGNORED_NAMESPACES.containsKey(namespace)) { throw new UnwantedDataException(IGNORED_NAMESPACES.get(namespace)); } if (ParseUri.TELEMETRY.equals(namespace) && IGNORED_TELEMETRY_DOCTYPES.containsKey(docType)) { throw new UnwantedDataException(IGNORED_TELEMETRY_DOCTYPES.get(docType)); } if ("FirefoxOS".equals(appName)) { throw new UnwantedDataException("1618684"); } if (ParseUri.TELEMETRY.equals(namespace) && FIREFOX_ONLY_DOCTYPES.contains(docType) && !"Firefox".equals(appName)) { throw new UnwantedDataException("1592010"); } if (bug1489560Affected(attributes, json)) { throw new AffectedByBugException("1489560"); } if ("default-browser-agent".equals(namespace) && "1".equals(docType)) { throw new AffectedByBugException("1626020"); } if (bug1602844Affected(attributes)) { json.path("events").elements().forEachRemaining(event -> { JsonNode eventMapValues = event.path(5); if (eventMapValues.has("fxauid")) { ((ObjectNode) eventMapValues).replace("fxauid", NullNode.getInstance()); } markBugCounter("1602844"); }); } if (bug1162183Affected(attributes)) { JsonNode payload = json.path("payload"); if (payload.has("slowSQL")) { ((ObjectNode) payload).remove("slowSQL"); markBugCounter("1162183"); } } if (bug1642386Affected(attributes)) { json.path("payload").path("syncs").elements().forEachRemaining(syncItem -> { syncItem.path("engines").elements().forEachRemaining(engine -> { ((ObjectNode) engine).remove("outgoing"); markBugCounter("1642386"); }); }); } }  }
MessageScrubber { public static void scrub(Map<String, String> attributes, ObjectNode json) throws MessageShouldBeDroppedException, AffectedByBugException { final String namespace = attributes.get(Attribute.DOCUMENT_NAMESPACE); final String docType = attributes.get(Attribute.DOCUMENT_TYPE); final String appName = attributes.get(Attribute.APP_NAME); final String appVersion = attributes.get(Attribute.APP_VERSION); final String appUpdateChannel = attributes.get(Attribute.APP_UPDATE_CHANNEL); final String appBuildId = attributes.get(Attribute.APP_BUILD_ID); if (ParseUri.TELEMETRY.equals(namespace) && "crash".equals(docType) && "nightly".equals(appUpdateChannel) && "20190719094503".equals(appBuildId) && Optional.of(json) .map(j -> j.path("payload").path("metadata").path("MozCrashReason").textValue()) .filter(s -> s.contains("do not use eval with system privileges")) .isPresent()) { throw new MessageShouldBeDroppedException("1567596"); } if (ParseUri.TELEMETRY.equals(namespace) && "crash".equals(docType) && (("nightly".equals(appUpdateChannel) && (appVersion.startsWith("68") || appVersion.startsWith("69"))) || ("beta".equals(appUpdateChannel) && appVersion.startsWith("68"))) && Optional.of(json) .map(j -> j.path("payload").path("metadata").path("RemoteType").textValue()) .filter(s -> s.startsWith("webIsolated=")) .isPresent()) { throw new MessageShouldBeDroppedException("1562011"); } if (ParseUri.TELEMETRY.equals(namespace) && "bhr".equals(docType) && (appVersion.startsWith("68") || appVersion.startsWith("69")) && Optional.of(json) .map(j -> j.path("payload").path("hangs").elements()) .map(Streams::stream).orElseGet(Stream::empty).map(j -> j.path("remoteType")) .filter(JsonNode::isTextual) .anyMatch(j -> j.textValue().startsWith("webIsolated="))) { throw new MessageShouldBeDroppedException("1562011"); } if (IGNORED_NAMESPACES.containsKey(namespace)) { throw new UnwantedDataException(IGNORED_NAMESPACES.get(namespace)); } if (ParseUri.TELEMETRY.equals(namespace) && IGNORED_TELEMETRY_DOCTYPES.containsKey(docType)) { throw new UnwantedDataException(IGNORED_TELEMETRY_DOCTYPES.get(docType)); } if ("FirefoxOS".equals(appName)) { throw new UnwantedDataException("1618684"); } if (ParseUri.TELEMETRY.equals(namespace) && FIREFOX_ONLY_DOCTYPES.contains(docType) && !"Firefox".equals(appName)) { throw new UnwantedDataException("1592010"); } if (bug1489560Affected(attributes, json)) { throw new AffectedByBugException("1489560"); } if ("default-browser-agent".equals(namespace) && "1".equals(docType)) { throw new AffectedByBugException("1626020"); } if (bug1602844Affected(attributes)) { json.path("events").elements().forEachRemaining(event -> { JsonNode eventMapValues = event.path(5); if (eventMapValues.has("fxauid")) { ((ObjectNode) eventMapValues).replace("fxauid", NullNode.getInstance()); } markBugCounter("1602844"); }); } if (bug1162183Affected(attributes)) { JsonNode payload = json.path("payload"); if (payload.has("slowSQL")) { ((ObjectNode) payload).remove("slowSQL"); markBugCounter("1162183"); } } if (bug1642386Affected(attributes)) { json.path("payload").path("syncs").elements().forEachRemaining(syncItem -> { syncItem.path("engines").elements().forEachRemaining(engine -> { ((ObjectNode) engine).remove("outgoing"); markBugCounter("1642386"); }); }); } }  static void scrub(Map<String, String> attributes, ObjectNode json); }
MessageScrubber { public static void scrub(Map<String, String> attributes, ObjectNode json) throws MessageShouldBeDroppedException, AffectedByBugException { final String namespace = attributes.get(Attribute.DOCUMENT_NAMESPACE); final String docType = attributes.get(Attribute.DOCUMENT_TYPE); final String appName = attributes.get(Attribute.APP_NAME); final String appVersion = attributes.get(Attribute.APP_VERSION); final String appUpdateChannel = attributes.get(Attribute.APP_UPDATE_CHANNEL); final String appBuildId = attributes.get(Attribute.APP_BUILD_ID); if (ParseUri.TELEMETRY.equals(namespace) && "crash".equals(docType) && "nightly".equals(appUpdateChannel) && "20190719094503".equals(appBuildId) && Optional.of(json) .map(j -> j.path("payload").path("metadata").path("MozCrashReason").textValue()) .filter(s -> s.contains("do not use eval with system privileges")) .isPresent()) { throw new MessageShouldBeDroppedException("1567596"); } if (ParseUri.TELEMETRY.equals(namespace) && "crash".equals(docType) && (("nightly".equals(appUpdateChannel) && (appVersion.startsWith("68") || appVersion.startsWith("69"))) || ("beta".equals(appUpdateChannel) && appVersion.startsWith("68"))) && Optional.of(json) .map(j -> j.path("payload").path("metadata").path("RemoteType").textValue()) .filter(s -> s.startsWith("webIsolated=")) .isPresent()) { throw new MessageShouldBeDroppedException("1562011"); } if (ParseUri.TELEMETRY.equals(namespace) && "bhr".equals(docType) && (appVersion.startsWith("68") || appVersion.startsWith("69")) && Optional.of(json) .map(j -> j.path("payload").path("hangs").elements()) .map(Streams::stream).orElseGet(Stream::empty).map(j -> j.path("remoteType")) .filter(JsonNode::isTextual) .anyMatch(j -> j.textValue().startsWith("webIsolated="))) { throw new MessageShouldBeDroppedException("1562011"); } if (IGNORED_NAMESPACES.containsKey(namespace)) { throw new UnwantedDataException(IGNORED_NAMESPACES.get(namespace)); } if (ParseUri.TELEMETRY.equals(namespace) && IGNORED_TELEMETRY_DOCTYPES.containsKey(docType)) { throw new UnwantedDataException(IGNORED_TELEMETRY_DOCTYPES.get(docType)); } if ("FirefoxOS".equals(appName)) { throw new UnwantedDataException("1618684"); } if (ParseUri.TELEMETRY.equals(namespace) && FIREFOX_ONLY_DOCTYPES.contains(docType) && !"Firefox".equals(appName)) { throw new UnwantedDataException("1592010"); } if (bug1489560Affected(attributes, json)) { throw new AffectedByBugException("1489560"); } if ("default-browser-agent".equals(namespace) && "1".equals(docType)) { throw new AffectedByBugException("1626020"); } if (bug1602844Affected(attributes)) { json.path("events").elements().forEachRemaining(event -> { JsonNode eventMapValues = event.path(5); if (eventMapValues.has("fxauid")) { ((ObjectNode) eventMapValues).replace("fxauid", NullNode.getInstance()); } markBugCounter("1602844"); }); } if (bug1162183Affected(attributes)) { JsonNode payload = json.path("payload"); if (payload.has("slowSQL")) { ((ObjectNode) payload).remove("slowSQL"); markBugCounter("1162183"); } } if (bug1642386Affected(attributes)) { json.path("payload").path("syncs").elements().forEachRemaining(syncItem -> { syncItem.path("engines").elements().forEachRemaining(engine -> { ((ObjectNode) engine).remove("outgoing"); markBugCounter("1642386"); }); }); } }  static void scrub(Map<String, String> attributes, ObjectNode json);  }