想到一个有关问题:代码有没有必要做ajax请求判断
想到一个问题:代码有没有必要做ajax请求判断
以前做ajax都没做过是否是ajax请求的判断。
有个新同事说要做判断,才注意到这个。
我查了很多站点 像优酷
他们都没做ajax获取的判断。
是否有必要做这个判断呢。
------解决方案--------------------
最好做,一般ajax请求的返回数据要求要高些
------解决方案--------------------
要看什么情况了,比如你的网站支持发布一个消息的功能,而这个是ajax请求,同时get方式传参即可。比如:msg.php?content=test。
那么如果你不做ajax判断的话,同时你的站点又是很火的那种站点(比如微博等),那么我就可以恶意攻击,在我的网站下面插入一个iframe,而这个iframe指向的是msg.php?content=我被攻击了, 那么一旦你访问我的站点,在你不知道的情况下,其实你的微博已经更新了一条消息“我被攻击了”,这是最常见的也是最简单的csrf攻击。
有的严重其实攻击渗透到银行流程中去,所以看你的需求了,ajax我建议还是做判断吧,最起码也要refer判断一下吧~
现在有些网站这种漏洞还是很严重的,两周前我还发现了一个已知的国内大型网站的这种漏洞,只要我在论坛里面发个帖子说大家都来看看(那个地址是我自己的测试服务器url),然后这个网站的一个投票数就会自动增多,很多人都在不知情的情况下帮我投票。。。
真心建议,做个判断吧~
------解决方案--------------------
关键看需求,程序说到底就是接收一个请求,返回一个结果
如果是可预见合理请求(在其他层次已经处理了不合理情况),就没必要在这个层次再判断
如果不可预见是否合理,则就算不是ajax也要做各种判断
例如表单提交,虽然客户端javascript做了判断,但仍然不能确定是否恶意提交
如果返回是面向一个特定的请求,例如API,那么肯定要检查的
至于攻击之类,难道不是ajax就不防范么?
记住一个原则:易入难出

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

Validator can be created by adding the following two lines in the controller.
