PDA

View Full Version : حرفه ای: امنیت هنگام صدا زدن یک درخواست آژاکس



zamoozegar
پنج شنبه 24 دی 1394, 11:05 صبح
سلام دوستان
من دقیقا سوالم اینه(متن سوال را از سایت انگلیسی کپی کردم چون خوب سوالم منو پرسیده بود)

میخام ببینم شما چطوری جلو این مشکل رو می گیرین

Imagine the next scenario: a user wants to register to a webpage and fills a form. While he is filling the form, jQuery keeps checking through a regular expression (http://en.wikipedia.org/wiki/Regular_expression) if fields are valid, etc...
Taking the email as the primary key which the user will use after registering to login, the email field needs to be checked with Ajax (http://en.wikipedia.org/wiki/Ajax_%28programming%29) to let the user know if that email is registered or not. I want to check it with Ajax to avoid sending the full form and emptying it, refreshing page, etc...
So, when the user has ended filling the email field, the Ajax request is sent to the server, something like the next link:
example.com/check.php?email=abcdefg@gmail.comWhen check.php receives the email, it asks the database if it exists or not and returns a message like: User already exists if user exists or null if user does not exist.
The question is: if someone digs through my .js and finds out links similar to that, they could use that link to send a large number of requests to find out if those random emails exist. This could lead to heavy use of the database or in the worst cases even crashing and private information leaks.
Someone could do a huge for loop to check emails like:
//Getting the response of the next links example.com/check.php?email=aaaaaaa@gmail.com // Returns null example.com/check.php?email=aaaaaab@gmail.com // Returns null example.com/check.php?email=aaaaaac@gmail.com // Returns null example.com/check.php?email=aaaaaad@gmail.com // Returns User already exists


یک مثال دیگه که من توش مشکل دارم اینه که من مثلا با آژاکس ی لیست 10 رکوردی می فرستم و باهاش ی جدول می سازم ،بعد رو هر کدوم که زد ویرایش من آی دی همون ردیف رو با آژاکس می فرستم به تابع ویرایش ،حالا مساله اینه اگه یکی با افزونه live http header بیاد درخواستی که سمت سرور می ره آی دی شو ی عدد دیگه بذاره میره ی رکوردی که بعضا ممکنه اصلا جز 10 رکوردی که قبلا بهش نمایش داده شده نباشه و مال دیگری رو ویرایش کنه
من تنها راهی به ذهنم رسید اینه که قبل از ویرایش در دیتابیس چک می کنم طرف این رکورد با این آی دی ماله خودشه یا نه (این کار رو در procedure , ویرایش انجام میدم) اما خب بنظرم باید راه ساده تری وجود داشته باشه

zamoozegar
شنبه 26 دی 1394, 04:57 صبح
سلام دوستان
من دقیقا سوالم اینه(متن سوال را از سایت انگلیسی کپی کردم چون خوب سوالم منو پرسیده بود)

میخام ببینم شما چطوری جلو این مشکل رو می گیرین

Imagine the next scenario: a user wants to register to a webpage and fills a form. While he is filling the form, jQuery keeps checking through a regular expression (http://en.wikipedia.org/wiki/Regular_expression) if fields are valid, etc...
Taking the email as the primary key which the user will use after registering to login, the email field needs to be checked with Ajax (http://en.wikipedia.org/wiki/Ajax_%28programming%29) to let the user know if that email is registered or not. I want to check it with Ajax to avoid sending the full form and emptying it, refreshing page, etc...
So, when the user has ended filling the email field, the Ajax request is sent to the server, something like the next link:
example.com/check.php?email=abcdefg@gmail.comWhen check.php receives the email, it asks the database if it exists or not and returns a message like: User already exists if user exists or null if user does not exist.
The question is: if someone digs through my .js and finds out links similar to that, they could use that link to send a large number of requests to find out if those random emails exist. This could lead to heavy use of the database or in the worst cases even crashing and private information leaks.
Someone could do a huge for loop to check emails like:
//Getting the response of the next links example.com/check.php?email=aaaaaaa@gmail.com // Returns null example.com/check.php?email=aaaaaab@gmail.com // Returns null example.com/check.php?email=aaaaaac@gmail.com // Returns null example.com/check.php?email=aaaaaad@gmail.com // Returns User already exists


یک مثال دیگه که من توش مشکل دارم اینه که من مثلا با آژاکس ی لیست 10 رکوردی می فرستم و باهاش ی جدول می سازم ،بعد رو هر کدوم که زد ویرایش من آی دی همون ردیف رو با آژاکس می فرستم به تابع ویرایش ،حالا مساله اینه اگه یکی با افزونه live http header بیاد درخواستی که سمت سرور می ره آی دی شو ی عدد دیگه بذاره میره ی رکوردی که بعضا ممکنه اصلا جز 10 رکوردی که قبلا بهش نمایش داده شده نباشه و مال دیگری رو ویرایش کنه
من تنها راهی به ذهنم رسید اینه که قبل از ویرایش در دیتابیس چک می کنم طرف این رکورد با این آی دی ماله خودشه یا نه (این کار رو در procedure , ویرایش انجام میدم) اما خب بنظرم باید راه ساده تری وجود داشته باشه


سلام
دوستانی که از آژاکس استفاده می کنن ، ممنون میشم راهنمایی کنید

ahmad156
شنبه 26 دی 1394, 22:23 عصر
ربطی به Ajax نداره و میتونه توی هر درخواستی این مشکلات پیش بیاد.یهترین گزینه بررسی، قبل از عملیات هست