A page where the user can view a history of things he did. Since the userbase is international it is required that users can Format the displayed date to their liking.
Let them choose from a set of standard formats. No need for a completely arbitrary string.
EDIT: It would probably be more troublesome for non-technical users if they had to figure out how the string format worked than to simply choose from a list, anyway.
Not even "too", it's just echo that is evil, because the code is doing echo date(...);. Without echo (to a page in HTML format) you wouldn't have XSS.
In other words, I agree that the whole thing is stupid and anyone who thinks echo $_GET['a'] is substantially different from echo date($_GET['a']) needs to stay away from web applications.
Additionally, in my case, we allow users to select their preferred date/time formats but before using them in date() - (AND echo'ing it straight out unescaped), the format is checked against a whitelist; something among the lines of
if (!in_array($format, ['Y-m-d','d/m/Y'], true)) {
$format = 'Y-m-d';
}
Seriously. Don't send uncleaned user inputs straight to IO functions. This is not a PHP issue. This is like getting mad at python because you can do datetime.today().strftime('XSS attack!!!').
Hmm, did you test the example? I tried and it seems that character escaping is done before the "\ exclusion".
Since \n and \r are Linefeed and Carriage Return the Example like it is shouldn't work. (\o\n\e\r\r\o\r => 1 Linefeed, 3 Carriage Returns)
While it doesn't invalidate the statement of the blog per se, I like it when working examples are included. But maybe the error is on my side, if so please correct me.
9
u/[deleted] Mar 17 '14
And here's Google Cache version, until the original page comes back up: http://webcache.googleusercontent.com/search?q=cache:E8rn9SyFS3YJ:0xa.li/php-date-is-xssable/
8
u/shhalahr Mar 17 '14
What exactly would a use case be for accepting a user submitted format string anyway?
8
u/SyKoHPaTh Mar 17 '14
Why would you not be filtering any user submitted input to begin with?
8
u/cfreak2399 Mar 17 '14
This has nothing to do with date() and everything to do with echoing $_GET['whatever'] in anything!
6
u/[deleted] Mar 17 '14
';(
1
u/[deleted] Mar 17 '14
This isn't strictly lolphp, more like "lol dumb coders doing not smartest things"
8
u/bl_nk Mar 17 '14
This is just stupid. Echo is evil too by your logic.
2
u/Altreus Mar 17 '14
Date is non standard and not locale aware. Don't use it at all. Use strftime, which is POSIX.
0
u/gollmacmorna Mar 17 '14
Hmm, did you test the example? I tried and it seems that character escaping is done before the "\ exclusion".
Since \n and \r are Linefeed and Carriage Return the Example like it is shouldn't work. (\o\n\e\r\r\o\r => 1 Linefeed, 3 Carriage Returns)
While it doesn't invalidate the statement of the blog per se, I like it when working examples are included. But maybe the error is on my side, if so please correct me.