防止在textarea中执行javascript

时间:2015-02-09 22:24:45

标签: javascript xss

我有一个textarea,您可以在其中标记其他人(使用自动完成和提及javascript插件),我注意到您可以输入:

<script>alert('hi');</script>

警报会执行,我不相信这是正常的行为,对于为什么会发生这种情况的任何想法?

HTML:

<div class="comment_details_input">
    <div class="comment_user_image"><img src="resource/user/profile/pic_c4ca4238a0b923820dcc509a6f75849b20762.jpeg"></div>

    <div class="mentions-input" style="display: block;"><div class="highlighter" style="white-space: pre-wrap; word-wrap: break-word; margin: 0px; padding: 6px 12px; border-width: 1px; font-size: 14px; font-style: normal; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 400; line-height: 20px; height: 54px; box-sizing: border-box; background-color: rgb(255, 255, 255);"><div class="highlighter-content"></div></div><textarea class="form-control comment_here input ui-autocomplete-input" type="text" placeholder="Write a comment" autocomplete="off" style="height: 54px; background-color: transparent;"></textarea><input type="hidden" value=""><ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content" id="ui-id-2" tabindex="0" style="display: none;"></ul></div>

    <div class="comment_details_input_hidden" style="display: block;">
        <button class="btn btn-sm btn_blue_lightbg pull-right add_comment ladda-button" data-style="slide-down">Post</button>
    </div>
</div>

使用Javascript:

这在textarea周围移动:

$(document).on('focus', '.comment_here', function () {

    $('.comment_here').autogrow();

    var $elem = $(this);
    $(this).parents('.mentions-input').next('.comment_details_input_hidden').slideDown("fast", function () {
        // Animation complete.
    });
});

$(document).on('keyup', '.comment_here', function () {
    var $elem = $(this);
    var height = $(this).height();

    var $highlighter = $elem.parents('.mentions-input').find('.highlighter');
    $highlighter.height(height);
});

使用的插件是jquery提及:

https://github.com/ivirabyan/jquery-mentions

编辑: 真的没有看到这是另一个问题的重复,他的问题是清理用户输入,我的问题是有一个textarea执行javascript。

0 个答案:

没有答案