views:

40

answers:

2

Hello everyone,

I'm trying to pass an SQL query string from a Java Applet to Servlet as a parameter.

Problem is that in Applet I have something say: sql=select * from p where(+p=1)

The resulting sql parameter in the Servlet is sql=select * from p where(+p=1).

So anyone knows how to prevent the browser from removing the + character from parameters?

Is there a escape character?

Thank you.

+3  A: 

Do not EVER do this. This is the direct way for the SQL injection (for example any user can insert the DELETE request to the get string and crash your server)

Juriy
Yeah I know...can't really do anything about it. Web application is an intranet so thats a relief.
Marquinio
I hate to be one of those infosec astronaut types, but the reality is most attacks on an application are internal. Although my employer is wonderful (ahem) and would never cause disgruntlement (cough cough) in its employees, your mileage may vary.
Paul
+3  A: 

You can use java.net.URLEncoder for this.

param = URLEncoder.encode(param, "UTF-8");

That said, the whole idea is leaky and very prone to attacks. One could easily reveal the URL and manually send a DELETE FROM p to it. Rather send commands as parameters, not complete SQL queries. Keep and hide the SQL queries in the server side.

BalusC
Hey that's a good idea. I'll try encoding the +. Thanks.
Marquinio
No, not only the `+`. The **whole** parameter value.
BalusC