Commit 8b1f4b14 authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Anonymize UUIDs and volume labels for external media

The output of 'lsblk' and 'blkid' are to be added to feedback logs.
However, UUIDs from blkid don't necessarily follow the expected UUID
pattern. Also, external media can contain user-defined volume labels.

Bug: 1045239
Change-Id: I972f1281755a204b0e6e9a554841f1a799c59a3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2016773Reviewed-by: default avatarIan Barkley-Yeung <iby@chromium.org>
Reviewed-by: default avatarJeffrey Kardatzke <jkardatzke@google.com>
Reviewed-by: default avatarJ Kardatzke <jkardatzke@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737963}
parent 975ac37a
......@@ -70,6 +70,22 @@ CustomPatternWithAlias kCustomPatternsWithContext[] = {
// GAIA IDs
{"GAIA", R"xxx((\"?\bgaia_id\"?[=:]['\"])(\d+)(\b['\"]))xxx"},
{"GAIA", R"xxx((\{id: )(\d+)(, email:))xxx"},
// UUIDs given by the 'blkid' tool. These don't necessarily look like
// standard UUIDs, so treat them specially.
{"UUID", R"xxx((UUID=")([0-9a-zA-Z-]+)("))xxx"},
// Volume labels presented in the 'blkid' tool, and as part of removable
// media paths shown in various logs such as cros-disks (in syslog).
// There isn't a well-defined format for these. For labels in blkid,
// capture everything between the open and closing quote.
{"Volume Label", R"xxx((LABEL=")([^"]+)("))xxx"},
// For paths, this is harder. The only restricted characters are '/' and
// NUL, so use a simple heuristic. cros-disks generally quotes paths using
// single-quotes, so capture everything until a quote character. For lsblk,
// capture everything until the end of the line, since the mount path is the
// last field.
{"Volume Label", R"xxx((/media/removable/)(.+?)(['"/\n]|$))xxx"},
};
bool MaybeUnmapAddress(net::IPAddress* addr) {
......
......@@ -510,4 +510,29 @@ TEST_F(AnonymizerToolTest, AnonymizeAndroidAppStoragePaths) {
}
#endif // defined(OS_CHROMEOS)
TEST_F(AnonymizerToolTest, AnonymizeBlockDevices) {
// Test cases in the form {input, output}.
std::pair<std::string, std::string> test_cases[] = {
// UUIDs that come from the 'blkid' tool.
{"PTUUID=\"985dff64-9c0f-3f49-945b-2d8c2e0238ec\"",
"PTUUID=\"<UUID: 1>\""},
{"UUID=\"E064-868C\"", "UUID=\"<UUID: 2>\""},
{"PARTUUID=\"7D242B2B1C751832\"", "PARTUUID=\"<UUID: 3>\""},
// Volume labels.
{"LABEL=\"ntfs\"", "LABEL=\"<Volume Label: 1>\""},
{"PARTLABEL=\"SD Card\"", "PARTLABEL=\"<Volume Label: 2>\""},
// Removable media paths.
{"/media/removable/SD Card/", "/media/removable/<Volume Label: 2>/"},
{"'/media/removable/My Secret Volume Name' don't redact this",
"'/media/removable/<Volume Label: 3>' don't redact this"},
{"0 part /media/removable/My Secret Volume Name With Spaces ",
"0 part /media/removable/<Volume Label: 4>"},
};
for (const auto p : test_cases) {
EXPECT_EQ(anonymizer_.Anonymize(p.first), p.second);
}
}
} // namespace feedback
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment