duanqiongchong0354 2018-09-18 19:03
浏览 108

保护我的php网页免受xss攻击

I have this piece of code which is a simple html page.

<?php


    require_once ("include/config.php");
    require_once($home."include/main_pre_body.php");
    require_once($home."pop-ups/email/email_form.php")

?>

<!DOCTYPE html>
<html>

    <head>
    <meta charset="utf-8" />
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" type="text/css" href="css/calendar.css" />
        <link rel="stylesheet" type="text/css" href="css/time.css" />
    </head>

    <Title><?php echo $EMAIL_TITLE_TEXT?></Title>

    <!--    Load Email Form Window  -->
    <body onload="OpenEmailWin()" style="margin:0px;">

<?php

    require_once($home."include/main_post_body.php");

?>

    </body>

</html>

I want to prevent all forms of possible xss attacks and i can identify a few but not all.

This is the first line <body onload="OpenEmailWin()" style="margin:0px;"> that i think shall be fixed. I have looked at xss vulnerbilities but the use of < and /> has surprised me the most. I got that from this answer https://stackoverflow.com/a/16126384/492293

Can the use of < and /> make a web page prone to xss attacks and what other parts of the simple page are vulnerable to a posile xss attack?

Thanks.

  • 写回答

1条回答 默认 最新

  • doujing2017 2018-09-18 20:00
    关注

    The two functions htmlspecialchars() and htmlentities() are gonna help you. Use these functions while getting data with POST or GET. like shown below:

    htmlspecialchars($_POST["example"]);
    htmlentities($_POST["example"]);
    

    or

    htmlspecialchars($_GET["example"]);
    htmlentities($_GET["example"]);
    
    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像