-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SendEmail: Protect users against vulnerable logmailers (#939)
glog is used on a variety of systems, and we must assume that some of them still use vulnerable mailers that have bugs or "interesting features" such as https://nvd.nist.gov/vuln/detail/CVE-2004-2771. Let's protect users against accidental shell injection by validating the email addresses against a slightly stricter version of the regex used by HTML5 to validate addresses[1]. This should prevent triggering any unexpected behavior in these tools. Also add some basic unit tests for the SendEmail method. [1] https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
- Loading branch information
Showing
4 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1489,3 +1489,31 @@ TEST(LogMsgTime, gmtoff) { | |
const long utc_max_offset = 50400; | ||
EXPECT_TRUE( (nGmtOff >= utc_min_offset) && (nGmtOff <= utc_max_offset) ); | ||
} | ||
|
||
TEST(EmailLogging, ValidAddress) { | ||
FlagSaver saver; | ||
FLAGS_logmailer = "/usr/bin/true"; | ||
|
||
EXPECT_TRUE(SendEmail("[email protected]", "Example subject", "Example body")); | ||
} | ||
|
||
TEST(EmailLogging, MultipleAddresses) { | ||
FlagSaver saver; | ||
FLAGS_logmailer = "/usr/bin/true"; | ||
|
||
EXPECT_TRUE(SendEmail("[email protected],[email protected]", "Example subject", "Example body")); | ||
} | ||
|
||
TEST(EmailLogging, InvalidAddress) { | ||
FlagSaver saver; | ||
FLAGS_logmailer = "/usr/bin/true"; | ||
|
||
EXPECT_FALSE(SendEmail("hello world@foo", "Example subject", "Example body")); | ||
} | ||
|
||
TEST(EmailLogging, MaliciousAddress) { | ||
FlagSaver saver; | ||
FLAGS_logmailer = "/usr/bin/true"; | ||
|
||
EXPECT_FALSE(SendEmail("!/bin/[email protected]", "Example subject", "Example body")); | ||
} |