duanchuang1935 2012-10-03 21:10
浏览 35
已采纳

在只与自身交互的PHP Web表单中,哪些验证很重要?

I made a simple base64 decoder form, which takes in an input through a textarea. I assume the input is base64 encoded. If it isn't base64 input, and there's a PHP error or garbage is returned, I don't mind at the moment However, from a security perspective do I need to do any validation or sanitation on this input?

The page is called error-decoder.php, and it submits to itself, and doesn't interact with a database or anything else. Here is the whole thing:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <div id="container" style="width: 80%; margin: 0 auto; font-family: sans-serif;">

            <form name="error-decoder" action="error-decoder.php" method="post">
                <textarea name="error-text-area" style="width: 100%; height: 400px;">
                    <?php if(!empty($_POST['error-text-area'])){ echo $_POST['error-text-area']; } ?>
                </textarea>
                <button type="submit" style="float: right;">Decode</button>
            </form>

            <?php
            if(!empty($_POST['error-text-area'])){
            ?>
                <p>Output:</p>
                <hr>
                <div id="error-output">
                <br />
            <?php
                echo base64_decode($_POST['error-text-area']) . "</div>";
            }
            ?>

        </div>

    </body>
</html>

Is there anything that needs to be done to make this safe either for the user or for my server? Are there important php.ini settings I need to worry about that would affect your answer? I don't care about errors or garbage except how it might affect security. Thanks for any info on this!

  • 写回答

3条回答 默认 最新

  • dsifjgogw48491752 2012-10-03 21:14
    关注

    You're using POST, so cross-site scripting is not possible, however local HTML/script injection is possible. The only security hole involves a user shooting themselves in the foot: If they submit base64 encoded malicious HTML/JS, they might end up redirecting themselves to a malicious page. So, sanitize the output of the decoding function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法