how to delay on this situation?

Hi all;I want to implement a session based flood control...when the flood is detected i want the servlet to be delayed for some seconds and then keep running.does this cause any cpu loads?or is it logical?please give me an idea...thank you
[267 byte] By [netsonicca] at [2007-11-26 18:47:36]
# 1
I don't think I understand the question. Do you have some technical meaning for "flood" here, or are you talking about actual water?Either way, what do you mean by the servlet being "delayed"? And why? And what's that got to do with the flood anyway?I'm very confused.
dcmintera at 2007-7-9 6:21:33 > top of Java-index,Java Essentials,Java Programming...
# 2
flood means posting too frequently here...For example if a user tries to post comments over the limits,its flood.limits will be defined by me...(for example over 5 posts in a minute will be defined as flood)
netsonicca at 2007-7-9 6:21:33 > top of Java-index,Java Essentials,Java Programming...
# 3

Ah, that makes loads more sense, thanks.

The principle of putting the thread that's servicing the incoming request is sound, but a problem arises if your malicious user sends multiple requests simultaneously.

You need to arrange to discard the "spare" offending requests, because if you create and block a thread for all of them that will cause you to run out of resources.

(edit) You don't necessarily need to use a Session, but you DO need to uniquely identify your incoming users. That can be by cookie. You could also take the approach of blocking by IP address (that can cause problems when one IP address is shared by a large number of users).

dcmintera at 2007-7-9 6:21:33 > top of Java-index,Java Essentials,Java Programming...
# 4

thanks for your recommendations...but if the user disables cookies from browser then my solution wont work...

i think it can be done with sessions...when flood detected the page will be redirected to a warning message like "plz try again later" and without delaying the thread...

what do you think?

netsonicca at 2007-7-9 6:21:33 > top of Java-index,Java Essentials,Java Programming...
# 5

> i think it can be done with sessions

Which proves only that you don't know how they work. How do you imagine the server keeps track of which user owns which session?

Bingo: generally a cookie (look for JSESSIONID). There's no quick fix here.

All the mechanisms that can be used to maintain a distinct session are susceptible to abuse by a malicious user. IP address identification isn't, but risks unfairly penalizing a user who's sharing an IP with an idiot.

dcmintera at 2007-7-9 6:21:33 > top of Java-index,Java Essentials,Java Programming...
# 6

I think If I were you I'd do this:

Track by IP address. If a "flood" of simultaneous posts appears to be coming from a particular IP address, enable the use of a CAPTCHA on the form(s) in question for that IP address only.

http://en.wikipedia.org/wiki/Captcha

That way you avoid inconveniencing nice guys, but make it too much hassle to bother for the SOBs.

dcmintera at 2007-7-9 6:21:33 > top of Java-index,Java Essentials,Java Programming...
# 7

got the idea but didnt understand about searching for ip adresses...they wont be stored in a db?will they?

you talked about jsessionid..i am searching about it but couldnt get valueable info...if you have any link write it and i will be very appreciated...

thanks a lot again

Burak

netsonicca at 2007-7-9 6:21:33 > top of Java-index,Java Essentials,Java Programming...
# 8

> got the idea but didnt understand about searching for

> ip adresses...they wont be stored in a db?will they?

No. But there's nothing to stop you from retaining this information. The IP address is available to servlets and filters as long as you're not behind any opaque infrastructure.

> you talked about jsessionid..i am searching about it

> but couldnt get valueable info...if you have any link

> write it and i will be very appreciated...

It's in the J2EE spec I presume, but it doesn't really matter - the point is that sessions are tracked in ways that are susceptible to manipulation by malicious end users.

>

> thanks a lot again

> Burak

dcmintera at 2007-7-9 6:21:33 > top of Java-index,Java Essentials,Java Programming...