当前位置:网站首页>XSS prevention
XSS prevention
2022-07-04 03:20:00 【Ma nongnong tattooed with Guan Ye】
TP6 Packaging usage steps :
① Use composer Carry out orders , install ezyang/htmlpurifier Extended class library
Under project directory
composer require ezyang/htmlpurifier
② stay app/common.php In the definition of remove_xss function
if (!function_exists('remove_xss')) {
// Use htmlpurifier To guard against xss attack
function remove_xss($string){
// relative index.php Entrance file , introduce HTMLPurifier.auto.php Core documents
//require_once './plugins/htmlpurifier/HTMLPurifier.auto.php';
// Generate configuration object
$cfg = HTMLPurifier_Config::createDefault();
// Here is the configuration :
$cfg -> set('Core.Encoding', 'UTF-8');
// Set the allowed HTML label
$cfg -> set('HTML.Allowed','div,b,strong,i,em,a[href|title],ul,ol,li,br,p[style],span[style],img[width|height|alt|src]');
// Set the allowed CSS Style attribute
$cfg -> set('CSS.AllowedProperties', 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align');
// Set up a Is it allowed to use... On the label target="_blank"
$cfg -> set('HTML.TargetBlank', TRUE);
// Use configuration to generate objects for filtering
$obj = new HTMLPurifier($cfg);
// Filter strings
return $obj -> purify($string);
}
}
explain :htmlpurifier plug-in unit , It will filter out script The label and what the label contains js Code .
The second kind : Encapsulate global filtering method
Set the global filtering method to htmlspecialchars
[ This method will make the payment function of the initial version unusable ]
| By default, the framework does not set any global filtering rules , You can app\Request Object filter Global filter properties : |
namespace app;
class Request extends \think\Request
{
protected $filter = ['htmlspecialchars'];
}————————————————
Copyright notice : This paper is about CSDN Blogger 「Doc_ACwhite」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/Doc_ACwhite/article/details/122924504
边栏推荐
- Package and download 10 sets of Apple CMS templates / download the source code of Apple CMS video and film website
- Global and Chinese markets of advanced X-ray inspection system (Axi) in PCB 2022-2028: Research Report on technology, participants, trends, market size and share
- Consul of distributed service registration discovery and unified configuration management
- Dare to climb here, you're not far from prison, reptile reverse actual combat case
- Recent learning fragmentation (14)
- Rhcsa day 3
- GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
- The property of judging odd or even numbers about XOR.
- Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
- Slurm view node configuration information
猜你喜欢

Unity controls the selection of the previous and next characters

MySQL query

Practical multifunctional toolbox wechat applet source code / support traffic master

Development of digital collection trading platform development of digital collection platform

Lichuang EDA learning notes 14: PCB board canvas settings

7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami

The 37 year old programmer was laid off, and he didn't find a job for 120 days. He had no choice but to go to a small company. As a result, he was confused
![[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)](/img/e9/818bdfeae766dca7d2318b52b4424d.jpg)
[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
随机推荐
Contest3145 - the 37th game of 2021 freshman individual training match_ J: Eat radish
Keepalived set the master not to recapture the VIP after fault recovery (it is invalid to solve nopreempt)
Network byte order
Handler source code analysis
7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
Consul of distributed service registration discovery and unified configuration management
Eh, the log time of MySQL server is less than 8h?
Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting
The difference between MCU serial communication and parallel communication and the understanding of UART
Leetcode51.n queen
Unity controls the selection of the previous and next characters
what does ctrl + d do?
How much does it cost to open a futures account in China? Where is it safe to open an account at present?
Have you entered the workplace since the first 00???
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
Buuctf QR code
The 37 year old programmer was laid off, and he didn't find a job for 120 days. He had no choice but to go to a small company. As a result, he was confused
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
JS object definition
There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection