Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在我的站点上放置JavaScript是否需要XSS注入之类的东西?_Javascript_Html - Fatal编程技术网

在我的站点上放置JavaScript是否需要XSS注入之类的东西?

在我的站点上放置JavaScript是否需要XSS注入之类的东西?,javascript,html,Javascript,Html,我一直在读XSS注射之类的东西,比如 <script>document.write('<a href="https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(document.URL)+'"target="_blank"title="Facebook"style="display:inline-block;vertical-align:middle;width:2em;height:2em;box-s

我一直在读XSS注射之类的东西,比如

<script>document.write('<a href="https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(document.URL)+'"target="_blank"title="Facebook"style="display:inline-block;vertical-align:middle;width:2em;height:2em;box-shadow:0 0 0 .1em #fff inset,.1em .1em 0.31em rgba(0,0,0,.3);background:#3b5998;"><svg style="display:block;fill:#fff;height:44%;margin:28% auto;" viewBox="0 -256 864 1664"><path transform="matrix(1,0,0,-1,-95,1280)" d="M 959,1524 V 1260 H 802 q -86,0 -116,-36 -30,-36 -30,-108 V 927 H 949 L 910,631 H 656 V -128 H 350 V 631 H 95 v 296 h 255 v 218 q 0,186 104,288.5 104,102.5 277,102.5 147,0 228,-12 z" /></svg></a> <a href="https://twitter.com/share?url='+encodeURIComponent(document.URL)+'&text='+encodeURIComponent(document.title)+'"target="_blank"title="Twitter"style="display:inline-block;vertical-align:middle;width:2em;height:2em;box-shadow:0 0 0 .1em #fff inset,.1em .1em 0.31em rgba(0,0,0,.3);background:#1b95e0;"><svg style="display:block;fill:#fff;height:36%;margin:32% auto;" viewBox="0 -256 1576 1280"><path transform="matrix(1,0,0,-1,-44,1024)" d="m 1620,1128 q -67,-98 -162,-167 1,-14 1,-42 0,-130 -38,-259.5 Q 1383,530 1305.5,411 1228,292 1121,200.5 1014,109 863,54.5 712,0 540,0 269,0 44,145 q 35,-4 78,-4 225,0 401,138 -105,2 -188,64.5 -83,62.5 -114,159.5 33,-5 61,-5 43,0 85,11 Q 255,532 181.5,620.5 108,709 108,826 v 4 q 68,-38 146,-41 -66,44 -105,115 -39,71 -39,154 0,88 44,163 Q 275,1072 448.5,982.5 622,893 820,883 q -8,38 -8,74 0,134 94.5,228.5 94.5,94.5 228.5,94.5 140,0 236,-102 109,21 205,78 -37,-115 -142,-178 93,10 186,50 z" /></svg></a>');</script>
document.write(“”);
这是一个社交媒体共享按钮


我认为字符串的“document.write”部分可以安全地放在我的HTML页面中,对吗?

只要字符串不受用户输入的影响(此处不受影响),您就可以了。如果它的用户受到影响,那么是的,如果它是您作为网站创建者所做的事情,那么它就不受用户输入的影响。document.URL是整个URL,它可以包括URL中的任何参数?someUserInput=。。。。但是,encodeURIComponent将负责对url进行编码,从而删除不安全的字符。如果没有encodeURIComponentbtw,则无论何时使用target=“\u blank”否,使用rel=“noopener noreferrer”都是危险的-它并不意味着进入iframe-我从这里了解到: