Looks like Null Byte Injection is possible in Java apps. see: Is null-byte injection possible in Java filenames?
So how does one protect against it? Inspect all the bytes of the filename for a 0 (zero) byte?
|
Looks like Null Byte Injection is possible in Java apps. see: Is null-byte injection possible in Java filenames? So how does one protect against it? Inspect all the bytes of the filename for a 0 (zero) byte? |
|||
|
|
|
Correct. If you allow untrusted input to affect any part of a filename, then you should apply proper input validation to protect yourself from attacks. You will need to protect yourself against not only null byte injection, but also path traversal and other attacks. My recommendation is to apply the following checks:
If you want to see some code from a separate project that contains these sorts of checks, albeit for a slightly different purpose, here's an example. |
||||
|
|
|
Control every input of you application. It's generally better to do a whitelist of good inputs then blacklist the bad ones.(You can easily forget on something in blacklisting, or new attack is discovered which is not blacklisted.) So I recommend checking it against some regular expression which should cover all possible inputs. |
|||
|
|