【问题标题】:Is wordpress comment form safe?wordpress 评论表单安全吗?
【发布时间】:2015-03-02 12:44:05
【问题描述】:

我有这个用于 cmets 的 Wordpress 表单,非常标准:

<form action="http://sitename.com/wp-comments-post.php" target="writeIframe" method="post" id="commentform" class="comment-form">
    <p class="comment-form-author">
        <label for="author">Your name</label>
        <input id="author" name="author" type="text" value="" size="30">
    </p>
    <p class="comment-form-comment">
        <label for="comment">Comment</label>
        <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>
    </p>
    <p class="form-submit">
        <input name="submit" type="submit" id="submit" class="submit" value="Send">
        <input type="hidden" name="comment_post_ID" value="1" id="comment_post_ID">
        <input type="hidden" name="comment_parent" id="comment_parent" value="0">
    </p>
</form>

它将用户输入数据发送到隐藏 iframe 内的 wp-cmets-post.php。这是开箱即用的 Wordpress 还是我应该添加代码以防止通过我的评论表单受到攻击?

【问题讨论】:

    标签: wordpress forms validation comments


    【解决方案1】:

    您是否看过使用 wp_nonce_field()。

    这是 WordPress codex 所说的:

    nonce 是一个“使用一次的数字”,用于帮助保护 URL 和表单免受某些类型的滥用。

    所以我肯定会建议你看看它并使用它。 转到此法典页面了解更多信息:

    http://codex.wordpress.org/WordPress_Nonces#Adding_a_nonce_to_a_form

    请阅读向表单添加随机数部分

    【讨论】:

    • 所以我将把以下内容作为我表单中的第一个字段,如下所示:
      等等
    • 是的,您还应该确保您正在验证 nonce 。您应该使用此代码来验证您的 nonce: if ( !isset( $_POST['my_nonce_name'] ) || ! wp_verify_nonce( $_POST['my_nonce_name'], 'my_nonce_action' ) ) { print '对不起,您的 nonce 没有核实。';出口; } else { //验证成功的代码 }
    • 这会在我的 cmets.php 文件的顶部吗? $retrieved_nonce = $_REQUEST['_wpnonce']; if (!wp_verify_nonce($retrived_nonce) ) die( '安全检查失败' );
    猜你喜欢
    • 2012-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-27
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多