Coding style question. PHP.

Status
Not open for further replies.

w00key

Ars Legatus Legionis
10,099
Subscriptor
What the heck, are people actually arguing against using template engines? It's just the same as SQL, if you don't force people to use prepared statements, they'll create SQL injection holes all over the place.


The right way to template nowadays is to auto escape everything and explicitely mark stuff as safe if needed and enable CSRF-protection by default - HTML isn't as safe as 10 years ago as everyone knows how to exploit any holes you leave in the code. (Examples are python based, PHP was too long ago for me)

The scary thing is that embedding <img src="http://yoursite/delete/everything"> to execute commands with the logged in user still works on a lot of sites. Even if you check for POST, there are ways around that; if any page echos anything from the request url back to the page, you can echo a <script> tag and execute a POST on the same domain. Usually it's a debug page left on the server - they aren't harmless, they are landmines.


Rewrite everything to index.php?path=$path so random .php's cannot be called, force everything through a template engine that takes care of escaping and CSRF and you'll have a chance to create a secure site. Otherwise, one missing htmlescapechars() can lead to disaster.
 
I think it's cleanest to push as much of the code to the client as possible. For example, with Java there's GWT, but there's an even better technique with PHP. Whenever I have a form, I put all my code that should run on submit in a hidden input and when the client submits the form, the server eval()s it. That way not only can I generate the code server-side, but I can also generate it client-side with JS, which makes the site extra dynamic. In fact, the PHP can generate the JS, which generates the next request's PHP, which can then generate the JS, etc. Normally savvy clients might view source and find a security hole but I'm one step ahead: I disable right click. Unfortunately Java doesn't have eval(), which forces you to separate your code and data the old fashioned way.
 

technophile

Ars Legatus Legionis
23,768
newwb":22ceav0g said:
I think it's cleanest to push as much of the code to the client as possible. For example, with Java there's GWT, but there's an even better technique with PHP. Whenever I have a form, I put all my code that should run on submit in a hidden input and when the client submits the form, the server eval()s it. That way not only can I generate the code server-side, but I can also generate it client-side with JS, which makes the site extra dynamic. In fact, the PHP can generate the JS, which generates the next request's PHP, which can then generate the JS, etc. Normally savvy clients might view source and find a security hole but I'm one step ahead: I disable right click. Unfortunately Java doesn't have eval(), which forces you to separate your code and data the old fashioned way.
You should switch to .NET; then you can pass an expression tree or IL to the client to be transformed and passed back to the server to be executed dynamically. I've done this with my last 3 clients and have gotten zero complaints as to security or performance.
 
technophile":18fbuaq9 said:
You should switch to .NET; then you can pass an expression tree or IL to the client to be transformed and passed back to the server to be executed dynamically. I've done this with my last 3 clients and have gotten zero complaints as to security or performance.

Oh, sweet. I feel like an idiot because I hadn't thought to map ngen.exe as in IIS handler before now.
Thanks!
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
1233928590_citizen%20kane%20clapping.gif
 
Status
Not open for further replies.