Skip to main content
13 events
when toggle format what by license comment
Mar 26, 2019 at 20:03 comment added Peter Cordes @user202729: Yeah, I would not recommend it in general. But I think it's worth considering if you're very paranoid about 2nd-order SQL injection, and that outweighs performance / size.
Mar 26, 2019 at 14:40 comment added user202729 @PeterCordes Regarding this particular case, that "extra layer" probably not provide extra security, but it unnecessarily bloats the data size. Definitely not a good practice.
Mar 25, 2019 at 21:51 comment added Peter Cordes This is kind of a belt-and-suspenders approach which is unnecessary if all your code is safe, and your DB admins don't build queries out of data from the DB. Even if that's the case, an extra layer of obscurity doesn't actively hurt. Just be sure not to rely on it as your primary defence. The security-through-obscurity argument isn't that every form of obscurity is bad, just that obscurity is not sufficient. (And that inventing your own unpublished cryptosystems is a terrible idea.) But I don't think the post was claiming that this is anything more than an extra layer vs. SQL injection.
Mar 25, 2019 at 21:49 comment added Peter Cordes The original tags on the question included [sql-injection]; only a day later did the OP add [xss]. The answer never explains the purpose of base64 encoding. It seems obvious to me that it's potentially useful as a way of storing arbitrary data in a DB without ever sending anything but plain text through SQL queries, not for defending against people stealing your database. And like I said, getting "nasty" data safely into your database with a prepared statement isn't always sufficient: 2nd-order SQL injection can attack unsafe interactive use of that data.
Mar 25, 2019 at 21:28 comment added Script47 Truth be told, some basic validation to ensure the input you are receiving is what you are expecting alongside prepared statements and on output using htmlspecialchars should solve majority of your issues.
Mar 25, 2019 at 21:26 comment added Script47 @PeterCordes with respect, I believe you have misunderstood the context. The question is asking about security, however the base64 method is security through obscurity i.e. encoding all the data so it is unreadable to a novice, I'm confident that any script kiddie worth their weight would know to that it is base64 and would then decode it trivially. The point of the editor to remove this specific paragraph was because security through obscurity is not a good principle to rely on when you have so many more sure fire ways to prevent XSS or SQL injection.
Mar 25, 2019 at 21:14 comment added Peter Cordes It seems like an ugly / inefficient solution, but worth considering if you don't trust other code or people who do queries on the database to always remember that data coming from the DB could still be malicious.
Mar 25, 2019 at 21:12 comment added Peter Cordes @AlexeiLevenkov is right: obscurity isn't the point; defeating SQL injection is the point. Base64 can't contain quote characters. (en.wikipedia.org/wiki/Base64#Base64_table). Encrypting seems pointless, but Base64 will work (at the expense of making indexing / searching on that field not usable). It's not a terrible idea for defending against 2nd-order and lateral SQL injection, when a later query (perhaps manually done by a DB admin) uses data from the DB as part of a query.
Mar 25, 2019 at 14:17 vote accept Script47
Mar 25, 2019 at 14:06 comment added Script47 @AlexeiLevenkov because the OP is suggesting to encode the data purely to prevent people from being able to see it in its original form thus making it trivially harder to edit, it was in a question to do with preventing XSS / other attacks therefore this method would definitely be seen as "security through obscurity".
Mar 25, 2019 at 14:03 comment added Alexei Levenkov I don't see why this particular case is "security through obscurity" as it clearly states "Base64 ...and then encrypting …" (converting bytes to Base64 and then again back to bytes for encryption does not sound … ideal … but definitely not insecure).
Mar 25, 2019 at 14:02 answer added Cerbrus timeline score: 36
Mar 25, 2019 at 13:55 history asked Script47 CC BY-SA 4.0