{"id":2025,"date":"2023-05-05T10:28:52","date_gmt":"2023-05-05T02:28:52","guid":{"rendered":"\/?p=2025"},"modified":"2023-05-05T10:28:52","modified_gmt":"2023-05-05T02:28:52","slug":"javascript%e5%ae%89%e5%85%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"\/?p=2025","title":{"rendered":"JavaScript\u5b89\u5168\u6307\u5357"},"content":{"rendered":"<h2>JavaScript\u9875\u9762\u7c7b<\/h2>\n<p><a id=\"1.1\"><\/a><\/p>\n<h3>I. \u4ee3\u7801\u5b9e\u73b0<\/h3>\n<p><a id=\"1.1.1\"><\/a><\/p>\n<h4>1.1 \u539f\u751fDOM API\u7684\u5b89\u5168\u64cd\u4f5c<\/h4>\n<p><strong>1.1.1\u3010\u5fc5\u987b\u3011HTML\u6807\u7b7e\u64cd\u4f5c\uff0c\u9650\u5b9a\/\u8fc7\u6ee4\u4f20\u5165\u53d8\u91cf\u503c<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528<code>innerHTML=<\/code>\u3001<code>outerHTML=<\/code>\u3001<code>document.write()<\/code>\u3001<code>document.writeln()<\/code>\u65f6\uff0c\u5982\u53d8\u91cf\u503c\u5916\u90e8\u53ef\u63a7\uff0c\u5e94\u5bf9\u7279\u6b8a\u5b57\u7b26\uff08<code>&amp;, &lt;, &gt;, &quot;, &#039;<\/code>\uff09\u505a\u7f16\u7801\u8f6c\u4e49\uff0c\u6216\u4f7f\u7528\u5b89\u5168\u7684DOM API\u66ff\u4ee3\uff0c\u5305\u62ec\uff1a<code>innerText=<\/code><\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ \u5047\u8bbe params \u4e3a\u7528\u6237\u8f93\u5165\uff0c text \u4e3a DOM \u8282\u70b9\n\/\/ bad\uff1a\u5c06\u4e0d\u53ef\u4fe1\u5185\u5bb9\u5e26\u5165HTML\u6807\u7b7e\u64cd\u4f5c\nconst { user } = params;\n\/\/ ...\ntext.innerHTML = `Follow @${user}`;\n\n\/\/ good: innerHTML\u64cd\u4f5c\u524d\uff0c\u5bf9\u7279\u6b8a\u5b57\u7b26\u7f16\u7801\u8f6c\u4e49\nfunction htmlEncode(iStr) {\n    let sStr = iStr;\n    sStr = sStr.replace(\/&amp;\/g, &quot;&amp;&quot;);\n    sStr = sStr.replace(\/&gt;\/g, &quot;&gt;&quot;);\n    sStr = sStr.replace(\/&lt;\/g, &quot;&lt;&quot;);\n    sStr = sStr.replace(\/&quot;\/g, &quot;&quot;&quot;);\n    sStr = sStr.replace(\/&#039;\/g, &quot;&amp;#39;&quot;);\n    return sStr;\n}\n\nlet { user } = params;\nuser = htmlEncode(user);\n\/\/ ...\ntext.innerHTML = `Follow @${user}`;\n\n\/\/ good: \u4f7f\u7528\u5b89\u5168\u7684DOM API\u66ff\u4ee3innerHTML\nconst { user } = params;\n\/\/ ...\ntext.innerText = `Follow @${user}`;<\/code><\/pre>\n<p><strong>1.1.2\u3010\u5fc5\u987b\u3011HTML\u5c5e\u6027\u64cd\u4f5c\uff0c\u9650\u5b9a\/\u8fc7\u6ee4\u4f20\u5165\u53d8\u91cf\u503c<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528<code>element.setAttribute(name, value);<\/code>\u65f6\uff0c\u5982\u7b2c\u4e00\u4e2a\u53c2\u6570\u503c<code>name<\/code>\u5916\u90e8\u53ef\u63a7\uff0c\u5e94\u7528\u767d\u540d\u5355\u9650\u5b9a\u5141\u8bb8\u64cd\u4f5c\u7684\u5c5e\u6027\u8303\u56f4\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528<code>element.setAttribute(name, value);<\/code>\u65f6\uff0c\u64cd\u4f5c<code>a.href<\/code>\u3001<code>ifame.src<\/code>\u3001<code>form.action<\/code>\u3001<code>embed.src<\/code>\u3001<code>object.data<\/code>\u3001<code>link.href<\/code>\u3001<code>area.href<\/code>\u3001<code>input.formaction<\/code>\u3001<code>button.formaction<\/code>\u5c5e\u6027\u65f6\uff0c\u5982\u7b2c\u4e8c\u4e2a\u53c2\u6570\u503c<code>value<\/code>\u5916\u90e8\u53ef\u63a7\uff0c\u5e94\u53c2\u8003<em>JavaScript\u9875\u9762\u7c7b\u89c4\u83031.3.1<\/em>\u90e8\u5206\uff0c\u9650\u5b9a\u9875\u9762\u91cd\u5b9a\u5411\u6216\u5f15\u5165\u8d44\u6e90\u7684\u76ee\u6807\u5730\u5740\u3002<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ good: setAttribute\u64cd\u4f5c\u524d\uff0c\u9650\u5b9a\u5f15\u5165\u8d44\u6e90\u7684\u76ee\u6807\u5730\u5740\nfunction addExternalCss(e) {\n    const t = document.createElement(&#039;link&#039;);\n    t.setAttribute(&#039;href&#039;, e),\n    t.setAttribute(&#039;rel&#039;, &#039;stylesheet&#039;),\n    t.setAttribute(&#039;type&#039;, &#039;text\/css&#039;),\n    document.head.appendChild(t)\n}\n\nfunction validURL(sUrl) {\n    return !!((\/^(https?:\\\/\\\/)?[\\w\\-.]+\\.(qq|tencent)\\.com($|\\\/|\\\\)\/i).test(sUrl) || (\/^[\\w][\\w\/.\\-_%]+$\/i).test(sUrl) || (\/^[\/\\\\][^\/\\\\]\/i).test(sUrl));\n}\n\nlet sUrl = &quot;https:\/\/evil.com\/1.css&quot;\nif (validURL(sUrl)) {\n    addExternalCss(sUrl);\n}<\/code><\/pre>\n<p><a id=\"1.1.2\"><\/a><\/p>\n<h4>1.2 \u6d41\u884c\u6846\u67b6\/\u5e93\u7684\u5b89\u5168\u64cd\u4f5c<\/h4>\n<p><strong>1.2.1\u3010\u5fc5\u987b\u3011\u9650\u5b9a\/\u8fc7\u6ee4\u4f20\u5165jQuery\u4e0d\u5b89\u5168\u51fd\u6570\u7684\u53d8\u91cf\u503c<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528<code>.html()<\/code>\u3001<code>.append()<\/code>\u3001<code>.prepend()<\/code>\u3001<code>.wrap()<\/code>\u3001<code>.replaceWith()<\/code>\u3001<code>.wrapAll()<\/code>\u3001<code>.wrapInner()<\/code>\u3001<code>.after()<\/code>\u3001<code>.before()<\/code>\u65f6\uff0c\u5982\u53d8\u91cf\u503c\u5916\u90e8\u53ef\u63a7\uff0c\u5e94\u5bf9\u7279\u6b8a\u5b57\u7b26\uff08<code>&amp;, &lt;, &gt;, &quot;, &#039;<\/code>\uff09\u505a\u7f16\u7801\u8f6c\u4e49\u3002<\/li>\n<li>\u5f15\u5165<code>jQuery 1.x\uff08\u7b49\u4e8e\u6216\u4f4e\u4e8e1.12\uff09\u3001jQuery2.x\uff08\u7b49\u4e8e\u6216\u4f4e\u4e8e2.2\uff09<\/code>\uff0c\u4e14\u4f7f\u7528<code>$()<\/code>\u65f6\uff0c\u5e94\u4f18\u5148\u8003\u8651\u66ff\u6362\u4e3a\u6700\u65b0\u7248\u672c\u3002\u5982\u4e00\u5b9a\u9700\u8981\u4f7f\u7528\uff0c\u5e94\u5bf9\u4f20\u5165\u53c2\u6570\u503c\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\uff08<code>&amp;, &lt;, &gt;, &quot;, &#039;<\/code>\uff09\u505a\u7f16\u7801\u8f6c\u4e49\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ bad\uff1a\u5c06\u4e0d\u53ef\u4fe1\u5185\u5bb9\uff0c\u5e26\u5165jQuery\u4e0d\u5b89\u5168\u51fd\u6570.after()\u64cd\u4f5c\nconst { user } = params;\n\/\/ ...\n$(&quot;p&quot;).after(user);\n\n\/\/ good: jQuery\u4e0d\u5b89\u5168\u51fd\u6570.html()\u64cd\u4f5c\u524d\uff0c\u5bf9\u7279\u6b8a\u5b57\u7b26\u7f16\u7801\u8f6c\u4e49\nfunction htmlEncode(iStr) {\n    let sStr = iStr;\n    sStr = sStr.replace(\/&amp;\/g, &quot;&amp;&quot;);\n    sStr = sStr.replace(\/&gt;\/g, &quot;&gt;&quot;);\n    sStr = sStr.replace(\/&lt;\/g, &quot;&lt;&quot;);\n    sStr = sStr.replace(\/&quot;\/g, &quot;&quot;&quot;);\n    sStr = sStr.replace(\/&#039;\/g, &quot;&amp;#39;&quot;);\n    return sStr;\n}\n\n\/\/ const user = params.user;\nuser = htmlEncode(user);\n\/\/ ...\n$(&quot;p&quot;).html(user);<\/code><\/pre>\n<ul>\n<li>\n<p>\u4f7f\u7528<code>.attr()<\/code>\u64cd\u4f5c<code>a.href<\/code>\u3001<code>ifame.src<\/code>\u3001<code>form.action<\/code>\u3001<code>embed.src<\/code>\u3001<code>object.data<\/code>\u3001<code>link.href<\/code>\u3001<code>area.href<\/code>\u3001<code>input.formaction<\/code>\u3001<code>button.formaction<\/code>\u5c5e\u6027\u65f6\uff0c\u5e94\u53c2\u8003<em>JavaScript\u9875\u9762\u7c7b\u89c4\u83031.3.1<\/em>\u90e8\u5206\uff0c\u9650\u5b9a\u91cd\u5b9a\u5411\u7684\u8d44\u6e90\u76ee\u6807\u5730\u5740\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528<code>.attr(attributeName, value)<\/code>\u65f6\uff0c\u5982\u7b2c\u4e00\u4e2a\u53c2\u6570\u503c<code>attributeName<\/code>\u5916\u90e8\u53ef\u63a7\uff0c\u5e94\u7528\u767d\u540d\u5355\u9650\u5b9a\u5141\u8bb8\u64cd\u4f5c\u7684\u5c5e\u6027\u8303\u56f4\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528<code>$.getScript(url [, success ])<\/code>\u65f6\uff0c\u5982\u7b2c\u4e00\u4e2a\u53c2\u6570\u503c<code>url<\/code>\u5916\u90e8\u53ef\u63a7\uff08\u5982\uff1a\u4eceURL\u53d6\u503c\u62fc\u63a5\uff0c\u8bf7\u6c42jsonp\u63a5\u53e3\uff09\uff0c\u5e94\u9650\u5b9a\u53ef\u63a7\u53d8\u91cf\u503c\u7684\u5b57\u7b26\u96c6\u8303\u56f4\u4e3a\uff1a<code>[a-zA-Z0-9_-]+<\/code>\u3002<\/p>\n<\/li>\n<\/ul>\n<p><strong>1.2.2\u3010\u5fc5\u987b\u3011\u9650\u5b9a\/\u8fc7\u6ee4\u4f20\u5165Vue.js\u4e0d\u5b89\u5168\u51fd\u6570\u7684\u53d8\u91cf\u503c<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528<code>v-html<\/code>\u65f6\uff0c\u4e0d\u5141\u8bb8\u5bf9\u7528\u6237\u63d0\u4f9b\u7684\u5185\u5bb9\u4f7f\u7528HTML\u63d2\u503c\u3002\u5982\u4e1a\u52a1\u9700\u8981\uff0c\u5e94\u5148\u5bf9\u4e0d\u53ef\u4fe1\u5185\u5bb9\u505a\u5bcc\u6587\u672c\u8fc7\u6ee4\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-html\">\/\/ bad\uff1a\u76f4\u63a5\u6e32\u67d3\u5916\u90e8\u4f20\u5165\u7684\u4e0d\u53ef\u4fe1\u5185\u5bb9\n&lt;div v-html=&quot;userProvidedHtml&quot;&gt;&lt;\/div&gt;\n\n\/\/ good\uff1a\u4f7f\u7528\u5bcc\u6587\u672c\u8fc7\u6ee4\u5e93\u5904\u7406\u4e0d\u53ef\u4fe1\u5185\u5bb9\u540e\u6e32\u67d3\n&lt;!-- \u4f7f\u7528 --&gt;\n&lt;div v-xss-html=&quot;{&#039;mode&#039;: &#039;whitelist&#039;, dirty: html, options: options}&quot; &gt;&lt;\/div&gt;\n\n&lt;!-- \u914d\u7f6e --&gt;\n&lt;script&gt;\n    new Vue({\n    el: &quot;#app&quot;,\n    data: {\n        options: {\n            whiteList: {\n                a: [&quot;href&quot;, &quot;title&quot;, &quot;target&quot;, &quot;class&quot;, &quot;id&quot;],\n                div: [&quot;class&quot;, &quot;id&quot;],\n                span: [&quot;class&quot;, &quot;id&quot;],\n                img: [&quot;src&quot;, &quot;alt&quot;],\n            },\n        },\n    },\n});\n&lt;\/script&gt;<\/code><\/pre>\n<ul>\n<li>\n<p>\u4f7f\u7528<code>v-bind<\/code>\u64cd\u4f5c<code>a.href<\/code>\u3001<code>ifame.src<\/code>\u3001<code>form.action<\/code>\u3001<code>embed.src<\/code>\u3001<code>object.data<\/code>\u3001<code>link.href<\/code>\u3001<code>area.href<\/code>\u3001<code>input.formaction<\/code>\u3001<code>button.formaction<\/code>\u65f6\uff0c\u5e94\u786e\u4fdd\u540e\u7aef\u5df2\u53c2\u8003<em>JavaScript\u9875\u9762\u7c7b\u89c4\u83031.3.1<\/em>\u90e8\u5206\uff0c\u9650\u5b9a\u4e86\u4f9b\u524d\u7aef\u8c03\u7528\u7684\u91cd\u5b9a\u5411\u76ee\u6807\u5730\u5740\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528<code>v-bind<\/code>\u64cd\u4f5c<code>style<\/code>\u5c5e\u6027\u65f6\uff0c\u5e94\u53ea\u5141\u8bb8\u5916\u90e8\u63a7\u5236\u7279\u5b9a\u3001\u53ef\u63a7\u7684CSS\u5c5e\u6027\u503c<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-html\">\/\/ bad\uff1av-bind\u5141\u8bb8\u5916\u90e8\u53ef\u63a7\u503c\uff0c\u81ea\u5b9a\u4e49CSS\u5c5e\u6027\u53ca\u6570\u503c\n&lt;a v-bind:href=&quot;sanitizedUrl&quot; v-bind:style=&quot;userProvidedStyles&quot;&gt;\nclick me\n&lt;\/a&gt;\n\n\/\/ good\uff1av-bind\u53ea\u5141\u8bb8\u5916\u90e8\u63d0\u4f9b\u7279\u6027\u3001\u53ef\u63a7\u7684CSS\u5c5e\u6027\u503c\n&lt;a v-bind:href=&quot;sanitizedUrl&quot; v-bind:style=&quot;{\ncolor: userProvidedColor,\nbackground: userProvidedBackground\n}&quot; &gt;\nclick me\n&lt;\/a&gt;<\/code><\/pre>\n<p><a id=\"1.1.3\"><\/a><\/p>\n<h4>1.3 \u9875\u9762\u91cd\u5b9a\u5411<\/h4>\n<p><strong>1.3.1\u3010\u5fc5\u987b\u3011\u9650\u5b9a\u8df3\u8f6c\u76ee\u6807\u5730\u5740<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u767d\u540d\u5355\uff0c\u9650\u5b9a\u91cd\u5b9a\u5411\u5730\u5740\u7684\u534f\u8bae\u524d\u7f00\uff08\u9ed8\u8ba4\u53ea\u5141\u8bb8HTTP\u3001HTTPS\uff09\u3001\u57df\u540d\uff08\u9ed8\u8ba4\u53ea\u5141\u8bb8\u516c\u53f8\u6839\u57df\uff09\uff0c\u6216\u6307\u5b9a\u4e3a\u56fa\u5b9a\u503c\uff1b<\/p>\n<\/li>\n<li>\n<p>\u9002\u7528\u573a\u666f\u5305\u62ec\uff0c\u4f7f\u7528\u51fd\u6570\u65b9\u6cd5\uff1a<code>location.href<\/code>\u3001<code>window.open()<\/code>\u3001<code>location.assign()<\/code>\u3001<code>location.replace()<\/code>\uff1b\u8d4b\u503c\u6216\u66f4\u65b0HTML\u5c5e\u6027\uff1a<code>a.href<\/code>\u3001<code>ifame.src<\/code>\u3001<code>form.action<\/code>\u3001<code>embed.src<\/code>\u3001<code>object.data<\/code>\u3001<code>link.href<\/code>\u3001<code>area.href<\/code>\u3001<code>input.formaction<\/code>\u3001<code>button.formaction<\/code>\uff1b<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ bad: \u8df3\u8f6c\u81f3\u5916\u90e8\u53ef\u63a7\u7684\u4e0d\u53ef\u4fe1\u5730\u5740\nconst sTargetUrl = getURLParam(&quot;target&quot;);\nlocation.replace(sTargetUrl);\n\n\/\/ good: \u767d\u540d\u5355\u9650\u5b9a\u91cd\u5b9a\u5411\u5730\u5740\nfunction validURL(sUrl) {\n    return !!((\/^(https?:\\\/\\\/)?[\\w\\-.]+\\.(qq|tencent)\\.com($|\\\/|\\\\)\/i).test(sUrl) || (\/^[\\w][\\w\/.\\-_%]+$\/i).test(sUrl) || (\/^[\/\\\\][^\/\\\\]\/i).test(sUrl));\n}\n\nconst sTargetUrl = getURLParam(&quot;target&quot;);\nif (validURL(sTargetUrl)) {\n    location.replace(sTargetUrl);\n}\n\n\/\/ good: \u5236\u5b9a\u91cd\u5b9a\u5411\u5730\u5740\u4e3a\u56fa\u5b9a\u503c\nconst sTargetUrl = &quot;http:\/\/www.qq.com&quot;;\nlocation.replace(sTargetUrl);<\/code><\/pre>\n<p><a id=\"1.1.4\"><\/a><\/p>\n<h4>1.4 JSON\u89e3\u6790\/\u52a8\u6001\u6267\u884c<\/h4>\n<p><strong>1.4.1\u3010\u5fc5\u987b\u3011\u4f7f\u7528\u5b89\u5168\u7684JSON\u89e3\u6790\u65b9\u5f0f<\/strong><\/p>\n<ul>\n<li>\u5e94\u4f7f\u7528<code>JSON.parse()<\/code>\u89e3\u6790JSON\u5b57\u7b26\u4e32\u3002\u4f4e\u7248\u672c\u6d4f\u89c8\u5668\uff0c\u5e94\u4f7f\u7528\u5b89\u5168\u7684<a href=\"https:\/\/github.com\/douglascrockford\/JSON-js\/blob\/master\/json2.js\">Polyfill\u5c01\u88c5<\/a><\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ bad: \u76f4\u63a5\u8c03\u7528eval\u89e3\u6790json\nconst sUserInput = getURLParam(&quot;json_val&quot;);\nconst jsonstr1 = `{&quot;name&quot;:&quot;a&quot;,&quot;company&quot;:&quot;b&quot;,&quot;value&quot;:&quot;${sUserInput}&quot;}`;\nconst json1 = eval(`(${jsonstr1})`);\n\n\/\/ good: \u4f7f\u7528JSON.parse\u89e3\u6790\nconst sUserInput = getURLParam(&quot;json_val&quot;);\nJSON.parse(sUserInput, (k, v) =&gt; {\n    if (k === &quot;&quot;) return v;\n    return v * 2;\n});\n\n\/\/ good: \u4f4e\u7248\u672c\u6d4f\u89c8\u5668\uff0c\u4f7f\u7528\u5b89\u5168\u7684Polyfill\u5c01\u88c5\uff08\u57fa\u4e8eeval\uff09\n&lt;script src=&quot;https:\/\/github.com\/douglascrockford\/JSON-js\/blob\/master\/json2.js&quot;&gt;&lt;\/script&gt;;\nconst sUserInput = getURLParam(&quot;json_val&quot;);\nJSON.parse(sUserInput);<\/code><\/pre>\n<p><a id=\"1.1.5\"><\/a><\/p>\n<h4>1.5 \u8de8\u57df\u901a\u8baf<\/h4>\n<p><strong>1.5.1\u3010\u5fc5\u987b\u3011\u4f7f\u7528\u5b89\u5168\u7684\u524d\u7aef\u8de8\u57df\u901a\u4fe1\u65b9\u5f0f<\/strong><\/p>\n<ul>\n<li>\u5177\u6709\u9694\u79bb\u767b\u5f55\u6001\uff08\u5982\uff1ap_skey\uff09\u3001\u6d89\u53ca\u7528\u6237\u9ad8\u654f\u611f\u4fe1\u606f\u7684\u4e1a\u52a1\uff08\u5982\uff1a\u5fae\u4fe1\u7f51\u9875\u7248\u3001QQ\u7a7a\u95f4\u3001QQ\u90ae\u7bb1\u3001\u516c\u4f17\u5e73\u53f0\uff09\uff0c\u7981\u6b62\u901a\u8fc7<code>document.domain<\/code>\u964d\u57df\uff0c\u5b9e\u73b0\u524d\u7aef\u8de8\u57df\u901a\u8baf\uff0c\u5e94\u4f7f\u7528postMessage\u66ff\u4ee3\u3002<\/li>\n<\/ul>\n<p><strong>1.5.2\u3010\u5fc5\u987b\u3011\u4f7f\u7528postMessage\u5e94\u9650\u5b9aOrigin<\/strong><\/p>\n<ul>\n<li>\n<p>\u5728message\u4e8b\u4ef6\u76d1\u542c\u56de\u8c03\u4e2d\uff0c\u5e94\u5148\u4f7f\u7528<code>event.origin<\/code>\u6821\u9a8c\u6765\u6e90\uff0c\u518d\u6267\u884c\u5177\u4f53\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<li>\n<p>\u6821\u9a8c\u6765\u6e90\u65f6\uff0c\u5e94\u4f7f\u7528<code>===<\/code>\u5224\u65ad\uff0c\u7981\u6b62\u4f7f\u7528<code>indexOf()<\/code><\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ bad: \u4f7f\u7528indexOf\u6821\u9a8cOrigin\u503c\nwindow.addEventListener(&quot;message&quot;, (e) =&gt; {\n    if (~e.origin.indexOf(&quot;https:\/\/a.qq.com&quot;)) {\n    \/\/ ...\n    } else {\n    \/\/ ...\n    }\n});\n\n\/\/ good: \u4f7f\u7528postMessage\u65f6\uff0c\u9650\u5b9aOrigin\uff0c\u4e14\u4f7f\u7528===\u5224\u65ad\nwindow.addEventListener(&quot;message&quot;, (e) =&gt; {\n    if (e.origin === &quot;https:\/\/a.qq.com&quot;) {\n    \/\/ ...\n    }\n});<\/code><\/pre>\n<p><a id=\"1.2\"><\/a><\/p>\n<h3>II. \u914d\u7f6e&amp;\u73af\u5883<\/h3>\n<p><a id=\"1.2.1\"><\/a><\/p>\n<h4>2.1 \u654f\u611f\/\u914d\u7f6e\u4fe1\u606f<\/h4>\n<p><strong>2.1.1\u3010\u5fc5\u987b\u3011\u7981\u6b62\u660e\u6587\u786c\u7f16\u7801AK\/SK<\/strong><\/p>\n<ul>\n<li>\u7981\u6b62\u524d\u7aef\u9875\u9762\u7684JS\u660e\u6587\u786c\u7f16\u7801AK\/SK\u7c7b\u5bc6\u94a5\uff0c\u5e94\u5c01\u88c5\u6210\u540e\u53f0\u63a5\u53e3\uff0cAK\/SK\u4fdd\u5b58\u5728\u540e\u7aef\u914d\u7f6e\u4e2d\u5fc3\u6216\u5bc6\u94a5\u7ba1\u7406\u7cfb\u7edf<\/li>\n<\/ul>\n<p><a id=\"1.2.2\"><\/a><\/p>\n<h4>2.2 \u7b2c\u4e09\u65b9\u7ec4\u4ef6\/\u8d44\u6e90<\/h4>\n<p><strong>2.2.1\u3010\u5fc5\u987b\u3011\u4f7f\u7528\u53ef\u4fe1\u8303\u56f4\u5185\u7684\u7edf\u8ba1\u7ec4\u4ef6<\/strong><\/p>\n<p><strong>2.2.2 \u3010\u5fc5\u987b\u3011\u7981\u6b62\u5f15\u5165\u975e\u53ef\u4fe1\u6765\u6e90\u7684\u7b2c\u4e09\u65b9JS<\/strong><\/p>\n<p><a id=\"1.2.3\"><\/a><\/p>\n<h4>2.3 \u7eb5\u6df1\u5b89\u5168\u9632\u62a4<\/h4>\n<p><strong>2.3.1\u3010\u63a8\u8350\u3011\u90e8\u7f72CSP\uff0c\u5e76\u542f\u7528\u4e25\u683c\u6a21\u5f0f<\/strong><\/p>\n<p><a id=\"2\"><\/a><\/p>\n<h2>Node.js\u540e\u53f0\u7c7b<\/h2>\n<p><a id=\"2.1\"><\/a><\/p>\n<h3>I. \u4ee3\u7801\u5b9e\u73b0<\/h3>\n<p><a id=\"2.1.1\"><\/a><\/p>\n<h4>1.1 \u8f93\u5165\u9a8c\u8bc1<\/h4>\n<p><strong>1.1.1\u3010\u5fc5\u987b\u3011\u6309\u7c7b\u578b\u8fdb\u884c\u6570\u636e\u6821\u9a8c<\/strong><\/p>\n<ul>\n<li>\u6240\u6709\u7a0b\u5e8f\u5916\u90e8\u8f93\u5165\u7684\u53c2\u6570\u503c\uff0c\u5e94\u8fdb\u884c\u6570\u636e\u6821\u9a8c\u3002\u6821\u9a8c\u5185\u5bb9\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a\u6570\u636e\u957f\u5ea6\u3001\u6570\u636e\u8303\u56f4\u3001\u6570\u636e\u7c7b\u578b\u4e0e\u683c\u5f0f\u3002\u6821\u9a8c\u4e0d\u901a\u8fc7\uff0c\u5e94\u62d2\u7edd\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ bad\uff1a\u672a\u8fdb\u884c\u8f93\u5165\u9a8c\u8bc1\nRouter.get(&quot;\/vulxss&quot;, (req, res) =&gt; {\n    const { txt } = req.query;\n    res.set(&quot;Content-Type&quot;, &quot;text\/html&quot;);\n    res.send({\n        data: txt,\n    });\n});\n\n\/\/ good\uff1a\u6309\u6570\u636e\u7c7b\u578b\uff0c\u8fdb\u884c\u8f93\u5165\u9a8c\u8bc1\nconst Router = require(&quot;express&quot;).Router();\nconst validator = require(&quot;validator&quot;);\n\nRouter.get(&quot;\/email_with_validator&quot;, (req, res) =&gt; {\n    const txt = req.query.txt || &quot;&quot;;\n    if (validator.isEmail(txt)) {\n        res.send({\n            data: txt,\n        });\n    } else {\n        res.send({ err: 1 });\n    }\n});<\/code><\/pre>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u7eb5\u6df1\u9632\u62a4\u63aa\u65bd - \u5b89\u5168\u6027\u589e\u5f3a\u7279\u6027<\/em><\/p>\n<p><a id=\"2.1.2\"><\/a><\/p>\n<h4>1.2 \u6267\u884c\u547d\u4ee4<\/h4>\n<p><strong>1.2.1 \u3010\u5fc5\u987b\u3011\u4f7f\u7528child_process\u6267\u884c\u7cfb\u7edf\u547d\u4ee4\uff0c\u5e94\u9650\u5b9a\u6216\u6821\u9a8c\u547d\u4ee4\u548c\u53c2\u6570\u7684\u5185\u5bb9<\/strong><\/p>\n<ul>\n<li>\n<p>\u9002\u7528\u573a\u666f\u5305\u62ec\uff1a<code>child_process.exec<\/code>, <code>child_process.execSync<\/code>, <code>child_process.spawn<\/code>, <code>child_process.spawnSync<\/code>, <code>child_process.execFile<\/code>, <code>child_process.execFileSync<\/code><\/p>\n<\/li>\n<li>\n<p>\u8c03\u7528\u4e0a\u8ff0\u51fd\u6570\uff0c\u5e94\u9996\u5148\u8003\u8651\u9650\u5b9a\u8303\u56f4\uff0c\u4f9b\u7528\u6237\u9009\u62e9\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528<code>child_process.exec<\/code>\u6216<code>child_process.execSync<\/code>\u65f6\uff0c\u5982\u679c\u53ef\u679a\u4e3e\u8f93\u5165\u7684\u53c2\u6570\u5185\u5bb9\u6216\u8005\u683c\u5f0f\uff0c\u5219\u5e94\u9650\u5b9a\u767d\u540d\u5355\u3002\u5982\u679c\u65e0\u6cd5\u679a\u4e3e\u547d\u4ee4\u6216\u53c2\u6570\uff0c\u5219\u5fc5\u987b\u8fc7\u6ee4\u6216\u8005\u8f6c\u4e49\u6307\u5b9a\u7b26\u53f7\uff0c\u5305\u62ec\uff1a``<code>|;&amp;$()&gt;&lt;<\/code>!```<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528<code>child_process.spawn<\/code> \u6216<code>child_process.execFile<\/code>\u65f6\uff0c\u5e94\u6821\u9a8c\u4f20\u5165\u7684\u547d\u4ee4\u548c\u53c2\u6570\u5728\u53ef\u63a7\u5217\u8868\u5185\u3002<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-js\">const Router = require(&quot;express&quot;).Router();\nconst validator = require(&quot;validator&quot;);\nconst { exec } = require(&#039;child_process&#039;);\n\n\/\/ bad\uff1a\u672a\u9650\u5b9a\u6216\u8fc7\u6ee4\uff0c\u76f4\u63a5\u6267\u884c\u547d\u4ee4\nRouter.get(&quot;\/vul_cmd_inject&quot;, (req, res) =&gt; {\n    const txt = req.query.txt || &quot;echo 1&quot;;\n    exec(txt, (err, stdout, stderr) =&gt; {\n        if (err) { res.send({ err: 1 }) }\n        res.send({stdout, stderr});\n    });\n});\n\n\/\/ good\uff1a\u901a\u8fc7\u767d\u540d\u5355\uff0c\u9650\u5b9a\u5916\u90e8\u53ef\u6267\u884c\u547d\u4ee4\u8303\u56f4\nRouter.get(&quot;\/not_vul_cmd_inject&quot;, (req, res) =&gt; {\n    const txt = req.query.txt || &quot;echo 1&quot;;\n  const phone = req.query.phone || &quot;&quot;;\n    const cmdList = {\n        sendmsg: &quot;.\/sendmsg &quot;\n    };\n    if (txt in cmdList &amp;&amp; validator.isMobilePhone(phone)) {\n        exec(cmdList[txt] + phone, (err, stdout, stderr) =&gt; {\n          if (err) { res.send({ err: 1 }) };\n          res.send({stdout, stderr});\n        });\n    } else {\n        res.send({\n            err: 1,\n            tips: `you can use &#039;${Object.keys(cmdList)}&#039;`,\n        });\n    }\n});\n\n\/\/ good\uff1a\u6267\u884c\u547d\u4ee4\u524d\uff0c\u8fc7\u6ee4\/\u8f6c\u4e49\u6307\u5b9a\u7b26\u53f7\nRouter.get(&quot;\/not_vul_cmd_inject&quot;, (req, res) =&gt; {\n    const txt = req.query.txt || &quot;echo 1&quot;;\n  let phone = req.query.phone || &quot;&quot;;\n    const cmdList = {\n        sendmsg: &quot;.\/sendmsg &quot;\n    };\n    phone = phone.replace(\/(\\||;|&amp;|\\$\\(|\\(|\\)|&gt;|&lt;|\\`|!)\/gi,&quot;&quot;);\n    if (txt in cmdList) {\n        exec(cmdList[txt] + phone, (err, stdout, stderr) =&gt; {\n          if (err) { res.send({ err: 1 }) };\n          res.send({stdout, stderr});\n        });\n    } else {\n        res.send({\n            err: 1,\n            tips: `you can use &#039;${Object.keys(cmdList)}&#039;`,\n        });\n    }\n});\n<\/code><\/pre>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u9ad8\u98ce\u9669 - \u4efb\u610f\u547d\u4ee4\u6267\u884c<\/em><\/p>\n<p><a id=\"2.1.3\"><\/a><\/p>\n<h4>1.3 \u6587\u4ef6\u64cd\u4f5c<\/h4>\n<p><strong>1.3.1 \u3010\u5fc5\u987b\u3011\u9650\u5b9a\u6587\u4ef6\u64cd\u4f5c\u7684\u540e\u7f00\u8303\u56f4<\/strong><\/p>\n<ul>\n<li>\u6309\u4e1a\u52a1\u9700\u6c42\uff0c\u4f7f\u7528\u767d\u540d\u5355\u9650\u5b9a\u540e\u7f00\u8303\u56f4\u3002<\/li>\n<\/ul>\n<p><strong>1.3.2 \u3010\u5fc5\u987b\u3011\u6821\u9a8c\u5e76\u9650\u5b9a\u6587\u4ef6\u8def\u5f84\u8303\u56f4<\/strong><\/p>\n<ul>\n<li>\u5e94\u56fa\u5b9a\u4e0a\u4f20\u3001\u8bbf\u95ee\u6587\u4ef6\u7684\u8def\u5f84\u3002\u82e5\u9700\u8981\u62fc\u63a5\u5916\u90e8\u53ef\u63a7\u53d8\u91cf\u503c\uff0c\u68c0\u67e5\u662f\u5426\u5305\u542b<code>..<\/code>\u3001<code>.<\/code>\u8def\u5f84\u7a7f\u8d8a\u5b57\u7b26\u3002\u5982\u5b58\u5728\uff0c\u5e94\u62d2\u7edd\u3002<\/li>\n<li>\u4f7f\u7528<code>fs<\/code>\u6a21\u5757\u4e0b\u7684\u51fd\u6570\u65b9\u6cd5\u65f6\uff0c\u5e94\u5bf9\u7b2c\u4e00\u4e2a\u53c2\u6570\u5373\u8def\u5f84\u90e8\u5206\u505a\u6821\u9a8c\uff0c\u68c0\u67e5\u662f\u5426\u5305\u542b\u8def\u5f84\u7a7f\u8d8a\u5b57\u7b26<code>.<\/code>\u6216<code>..<\/code>\u3002\u6d89\u53ca\u65b9\u6cd5\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<code>fs.truncate<\/code>\u3001<code>fs.truncateSync<\/code>\u3001<code>fs.chown<\/code>\u3001<code>fs.chownSync<\/code>\u3001<code>fs.lchown<\/code>\u3001<code>fs.lchownSync<\/code>\u3001<code>fs.stat<\/code>\u3001<code>fs.lchmodSync<\/code>\u3001<code>fs.lstat<\/code>\u3001<code>fs.statSync<\/code>\u3001<code>fs.lstatSync<\/code>\u3001<code>fs.readlink<\/code>\u3001<code>fs.unlink<\/code>\u3001<code>fs.unlinkSync<\/code>\u3001<code>fs.rmdir<\/code>\u3001<code>fs.rmdirSync<\/code>\u3001<code>fs.mkdir<\/code>\u3001<code>fs.mkdirSync<\/code>\u3001<code>fs.readdir<\/code>\u3001<code>fs.readdirSync<\/code>\u3001<code>fs.openSync<\/code>\u3001<code>fs.open<\/code>\u3001<code>fs.createReadStream<\/code>\u3001<code>fs.createWriteStream<\/code><\/li>\n<li>\u4f7f\u7528express\u6846\u67b6\u7684<code>sendFile<\/code>\u65b9\u6cd5\u65f6\uff0c\u5e94\u5bf9\u7b2c\u4e00\u4e2a\u53c2\u6570\u5373\u8def\u5f84\u90e8\u5206\u505a\u6821\u9a8c\uff0c\u68c0\u67e5\u662f\u5426\u5305\u542b\u8def\u5f84\u7a7f\u8d8a\u5b57\u7b26<code>.<\/code>\u6216<code>..<\/code><\/li>\n<li>\u6821\u9a8c\u65f6\uff0c\u5e94\u4f7f\u7528<code>path<\/code>\u6a21\u5757\u5904\u7406\u524d\u7684\u8def\u5f84\u53c2\u6570\u503c\uff0c\u6216\u5224\u65ad\u5904\u7406\u8fc7\u540e\u7684\u8def\u5f84\u662f\u5426\u7a7f\u8d8a\u51fa\u4e86\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u3002\u6d89\u53ca\u65b9\u6cd5\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<code>path.resolve<\/code>\u3001<code>path.join<\/code>\u3001<code>path.normalize<\/code>\u7b49<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">const fs = require(&quot;fs&quot;);\nconst path = require(&quot;path&quot;);\nlet filename = req.query.ufile;\nlet root = &#039;\/data\/ufile&#039;;\n\n\/\/ bad\uff1a\u672a\u68c0\u67e5\u6587\u4ef6\u540d\/\u8def\u5f84\nfs.readFile(root + filename, (err, data) =&gt; {\n    if (err) {\n        return console.error(err);\n    }\n    console.log(`\u5f02\u6b65\u8bfb\u53d6: ${data.toString()}`);\n});\n\n\/\/ bad\uff1a\u4f7f\u7528path\u5904\u7406\u8fc7\u540e\u7684\u8def\u5f84\u53c2\u6570\u503c\u505a\u6821\u9a8c\uff0c\u4ecd\u53ef\u80fd\u6709\u8def\u5f84\u7a7f\u8d8a\u98ce\u9669\nfilename = path.join(root, filename);\nif (filename.indexOf(&quot;..&quot;) &lt; 0) {\n    fs.readFile(filename, (err, data) =&gt; {\n        if (err) {\n            return console.error(err);\n        }\n        console.log(data.toString());\n    });\n};\n\n\/\/ good\uff1a\u68c0\u67e5\u4e86\u6587\u4ef6\u540d\/\u8def\u5f84\uff0c\u662f\u5426\u5305\u542b\u8def\u5f84\u7a7f\u8d8a\u5b57\u7b26\nif (filename.indexOf(&quot;..&quot;) &lt; 0) {\n    filename = path.join(root, filename);\n    fs.readFile(filename, (err, data) =&gt; {\n        if (err) {\n            return console.error(err);\n        }\n        console.log(data.toString());\n    });\n};<\/code><\/pre>\n<p><strong>1.3.3 \u3010\u5fc5\u987b\u3011\u5b89\u5168\u5730\u5904\u7406\u4e0a\u4f20\u6587\u4ef6\u540d<\/strong><\/p>\n<ul>\n<li>\u5c06\u4e0a\u4f20\u6587\u4ef6\u91cd\u547d\u540d\u4e3a16\u4f4d\u4ee5\u4e0a\u7684\u968f\u673a\u5b57\u7b26\u4e32\u4fdd\u5b58\u3002<\/li>\n<li>\u5982\u9700\u539f\u6837\u4fdd\u7559\u6587\u4ef6\u540d\uff0c\u5e94\u68c0\u67e5\u662f\u5426\u5305\u542b<code>..<\/code>\u3001<code>.<\/code>\u8def\u5f84\u7a7f\u8d8a\u5b57\u7b26\u3002\u5982\u5b58\u5728\uff0c\u5e94\u62d2\u7edd\u3002<\/li>\n<\/ul>\n<p><strong>1.3.4 \u3010\u5fc5\u987b\u3011\u654f\u611f\u8d44\u6e90\u6587\u4ef6\uff0c\u5e94\u6709\u52a0\u5bc6\u3001\u9274\u6743\u548c\u6c34\u5370\u7b49\u52a0\u56fa\u63aa\u65bd<\/strong><\/p>\n<ul>\n<li>\u7528\u6237\u4e0a\u4f20\u7684<code>\u8eab\u4efd\u8bc1<\/code>\u3001<code>\u94f6\u884c\u5361<\/code>\u7b49\u56fe\u7247\uff0c\u5c5e\u654f\u611f\u8d44\u6e90\u6587\u4ef6\uff0c\u5e94\u91c7\u53d6\u5b89\u5168\u52a0\u56fa\u3002<\/li>\n<li>\u6307\u5411\u6b64\u7c7b\u6587\u4ef6\u7684URL\uff0c\u5e94\u4fdd\u8bc1\u4e0d\u53ef\u9884\u6d4b\u6027\uff1b\u540c\u65f6\uff0c\u786e\u4fdd\u65e0\u63a5\u53e3\u4f1a\u6279\u91cf\u5c55\u793a\u6b64\u7c7b\u8d44\u6e90\u7684URL\u3002<\/li>\n<li>\u8bbf\u95ee\u654f\u611f\u8d44\u6e90\u6587\u4ef6\u65f6\uff0c\u5e94\u8fdb\u884c\u6743\u9650\u63a7\u5236\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4ec5\u7528\u6237\u53ef\u67e5\u770b\u3001\u64cd\u4f5c\u81ea\u8eab\u654f\u611f\u8d44\u6e90\u6587\u4ef6\u3002<\/li>\n<li>\u56fe\u7247\u7c7b\u6587\u4ef6\u5e94\u6dfb\u52a0\u4e1a\u52a1\u6c34\u5370\uff0c\u8868\u660e\u8be5\u56fe\u7247\u4ec5\u53ef\u7528\u4e8e\u5f53\u524d\u4e1a\u52a1\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<p><a id=\"2.1.4\"><\/a><\/p>\n<h4>1.4 \u7f51\u7edc\u8bf7\u6c42<\/h4>\n<p><strong>1.4.1 \u3010\u5fc5\u987b\u3011\u9650\u5b9a\u8bbf\u95ee\u7f51\u7edc\u8d44\u6e90\u5730\u5740\u8303\u56f4<\/strong><\/p>\n<ul>\n<li>\n<p>\u5e94\u56fa\u5b9a\u7a0b\u5e8f\u8bbf\u95ee\u7f51\u7edc\u8d44\u6e90\u5730\u5740\u7684<code>\u534f\u8bae<\/code>\u3001<code>\u57df\u540d<\/code>\u3001<code>\u8def\u5f84<\/code>\u8303\u56f4\u3002<\/p>\n<\/li>\n<li>\n<p>\u82e5\u4e1a\u52a1\u9700\u8981\uff0c\u5916\u90e8\u53ef\u6307\u5b9a\u8bbf\u95ee\u7f51\u7edc\u8d44\u6e90\u5730\u5740\uff0c\u5e94\u7981\u6b62\u8bbf\u95ee\u5185\u7f51\u79c1\u6709\u5730\u5740\u6bb5\u53ca\u57df\u540d\u3002<\/p>\n<\/li>\n<\/ul>\n<pre><code>\/\/ \u4ee5RFC\u5b9a\u4e49\u7684\u4e13\u6709\u7f51\u7edc\u4e3a\u4f8b\uff0c\u5982\u6709\u81ea\u5b9a\u4e49\u79c1\u6709\u7f51\u6bb5\u4ea6\u5e94\u52a0\u5165\u7981\u6b62\u8bbf\u95ee\u5217\u8868\u3002\n10.0.0.0\/8\n172.16.0.0\/12\n192.168.0.0\/16\n127.0.0.0\/8<\/code><\/pre>\n<p><strong>1.4.2 \u3010\u63a8\u8350\u3011\u8bf7\u6c42\u7f51\u7edc\u8d44\u6e90\uff0c\u5e94\u52a0\u5bc6\u4f20\u8f93<\/strong><\/p>\n<ul>\n<li>\u5e94\u4f18\u5148\u9009\u7528https\u534f\u8bae\u8bf7\u6c42\u7f51\u7edc\u8d44\u6e90<\/li>\n<\/ul>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u9ad8\u98ce\u9669 - SSRF\uff0c\u9ad8\u98ce\u9669 - HTTP\u52ab\u6301<\/em><\/p>\n<p><a id=\"2.1.5\"><\/a><\/p>\n<h4>1.5 \u6570\u636e\u8f93\u51fa<\/h4>\n<p><strong>1.5.1 \u3010\u5fc5\u987b\u3011\u9ad8\u654f\u611f\u4fe1\u606f\u7981\u6b62\u5b58\u50a8\u3001\u5c55\u793a<\/strong><\/p>\n<ul>\n<li>\u53e3\u4ee4\u3001\u5bc6\u4fdd\u7b54\u6848\u3001\u751f\u7406\u6807\u8bc6\u7b49\u9274\u6743\u4fe1\u606f\u7981\u6b62\u5c55\u793a<\/li>\n<li>\u975e\u91d1\u878d\u7c7b\u4e1a\u52a1\uff0c\u4fe1\u7528\u5361cvv\u7801\u53ca\u65e5\u5fd7\u7981\u6b62\u5b58\u50a8<\/li>\n<\/ul>\n<p><strong>1.5.2\u3010\u5fc5\u987b\u3011\u4e00\u822c\u654f\u611f\u4fe1\u606f\u8131\u654f\u5c55\u793a<\/strong><\/p>\n<ul>\n<li>\u8eab\u4efd\u8bc1\u53ea\u663e\u793a\u7b2c\u4e00\u4f4d\u548c\u6700\u540e\u4e00\u4f4d\u5b57\u7b26\uff0c\u5982\uff1a<code>3*********************1<\/code><\/li>\n<li>\u79fb\u52a8\u7535\u8bdd\u53f7\u7801\u9690\u85cf\u4e2d\u95f46\u4f4d\u5b57\u7b26\uff0c\u5982\uff1a<code>134***************48<\/code><\/li>\n<li>\u5de5\u4f5c\u5730\u5740\/\u5bb6\u5ead\u5730\u5740\u6700\u591a\u663e\u793a\u5230<code>\u533a<\/code>\u4e00\u7ea7<\/li>\n<li>\u94f6\u884c\u5361\u53f7\u4ec5\u663e\u793a\u6700\u540e4\u4f4d\u5b57\u7b26\uff0c\u5982\uff1a<code>*********************8639<\/code><\/li>\n<\/ul>\n<p><strong>1.5.3 \u3010\u63a8\u8350\u3011\u8fd4\u56de\u7684\u5b57\u6bb5\u6309\u4e1a\u52a1\u9700\u8981\u8f93\u51fa<\/strong><\/p>\n<ul>\n<li>\u6309\u9700\u8f93\u51fa\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u7528\u6237\u4fe1\u606f\u6cc4\u9732<\/li>\n<li>\u7528\u6237\u654f\u611f\u6570\u636e\u5e94\u5728\u670d\u52a1\u5668\u540e\u53f0\u5904\u7406\u540e\u8f93\u51fa\uff0c\u4e0d\u53ef\u4ee5\u5148\u8f93\u51fa\u5230\u5ba2\u6237\u7aef\uff0c\u518d\u901a\u8fc7\u5ba2\u6237\u7aef\u4ee3\u7801\u6765\u5904\u7406\u5c55\u793a<\/li>\n<\/ul>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u9ad8\u98ce\u9669 - \u7528\u6237\u654f\u611f\u4fe1\u606f\u6cc4\u9732<\/em><\/p>\n<p><a id=\"2.1.6\"><\/a><\/p>\n<h4>1.6 \u54cd\u5e94\u8f93\u51fa<\/h4>\n<p><strong>1.6.1 \u3010\u5fc5\u987b\u3011\u8bbe\u7f6e\u6b63\u786e\u7684HTTP\u54cd\u5e94\u5305\u7c7b\u578b<\/strong><\/p>\n<ul>\n<li>\u54cd\u5e94\u5934Content-Type\u4e0e\u5b9e\u9645\u54cd\u5e94\u5185\u5bb9\uff0c\u5e94\u4fdd\u6301\u4e00\u81f4\u3002\u5982\uff1aAPI\u54cd\u5e94\u6570\u636e\u7c7b\u578b\u662fjson\uff0c\u5219\u54cd\u5e94\u5934\u4f7f\u7528<code>application\/json<\/code>\uff1b\u82e5\u4e3axml\uff0c\u5219\u8bbe\u7f6e\u4e3a<code>text\/xml<\/code>\u3002<\/li>\n<\/ul>\n<p><strong>1.6.2 \u3010\u5fc5\u987b\u3011\u6dfb\u52a0\u5b89\u5168\u54cd\u5e94\u5934<\/strong><\/p>\n<ul>\n<li>\u6240\u6709\u63a5\u53e3\u3001\u9875\u9762\uff0c\u6dfb\u52a0\u54cd\u5e94\u5934 <code>X-Content-Type-Options: nosniff<\/code>\u3002<\/li>\n<li>\u6240\u6709\u63a5\u53e3\u3001\u9875\u9762\uff0c\u6dfb\u52a0\u54cd\u5e94\u5934<code>X-Frame-Options <\/code>\u3002\u6309\u9700\u5408\u7406\u8bbe\u7f6e\u5176\u5141\u8bb8\u8303\u56f4\uff0c\u5305\u62ec\uff1a<code>DENY<\/code>\u3001<code>SAMEORIGIN<\/code>\u3001<code>ALLOW-FROM origin<\/code>\u3002\u7528\u6cd5\u53c2\u8003\uff1a<a href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/X-Frame-Options\">MDN\u6587\u6863<\/a><\/li>\n<li>\u63a8\u8350\u4f7f\u7528\u7ec4\u4ef6\uff1a <a href=\"https:\/\/www.npmjs.com\/package\/helmet\">helmet<\/a> <\/li>\n<\/ul>\n<p><strong>1.6.3 \u3010\u5fc5\u987b\u3011\u5916\u90e8\u8f93\u5165\u62fc\u63a5\u5230\u54cd\u5e94\u9875\u9762\u524d\uff0c\u8fdb\u884c\u7f16\u7801\u5904\u7406<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u573a\u666f<\/th>\n<th>\u7f16\u7801\u89c4\u5219<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u8f93\u51fa\u70b9\u5728HTML\u6807\u7b7e\u4e4b\u95f4<\/td>\n<td>\u9700\u8981\u5bf9\u4ee5\u4e0b6\u4e2a\u7279\u6b8a\u5b57\u7b26\u8fdb\u884cHTML\u5b9e\u4f53\u7f16\u7801(&amp;, &lt;, &gt;, &quot;, ',\/)\u3002<br \/>\u793a\u4f8b\uff1a<br \/>&amp; --&gt; &amp;amp;<br \/>&lt; --&gt; &amp;lt;<br \/>&gt;--&gt; &amp;gt;<br \/>&quot; --&gt; &amp;quot;<br \/>' --&gt; &amp;#x27;  <br \/>\/ --&gt; &amp;#x2F;<\/td>\n<\/tr>\n<tr>\n<td>\u8f93\u51fa\u70b9\u5728HTML\u6807\u7b7e\u666e\u901a\u5c5e\u6027\u5185\uff08\u5982href\u3001src\u3001style\u7b49\uff0con\u4e8b\u4ef6\u9664\u5916\uff09<\/td>\n<td>\u8981\u5bf9\u6570\u636e\u8fdb\u884cHTML\u5c5e\u6027\u7f16\u7801\u3002<br \/>\u7f16\u7801\u89c4\u5219\uff1a\u9664\u4e86\u963f\u62c9\u4f2f\u6570\u5b57\u548c\u5b57\u6bcd\uff0c\u5bf9\u5176\u4ed6\u6240\u6709\u7684\u5b57\u7b26\u8fdb\u884c\u7f16\u7801\uff0c\u53ea\u8981\u8be5\u5b57\u7b26\u7684ASCII\u7801\u5c0f\u4e8e256\u3002\u7f16\u7801\u540e\u8f93\u51fa\u7684\u683c\u5f0f\u4e3a&#xHH;(\u4ee5&amp;#x\u5f00\u5934\uff0cHH\u5219\u662f\u6307\u8be5\u5b57\u7b26\u5bf9\u5e94\u7684\u5341\u516d\u8fdb\u5236\u6570\u5b57\uff0c\u5206\u53f7\u4f5c\u4e3a\u7ed3\u675f\u7b26)<\/td>\n<\/tr>\n<tr>\n<td>\u8f93\u51fa\u70b9\u5728JS\u5185\u7684\u6570\u636e\u4e2d<\/td>\n<td>\u9700\u8981\u8fdb\u884cjs\u7f16\u7801<br \/>\u7f16\u7801\u89c4\u5219\uff1a<br \/>\u9664\u4e86\u963f\u62c9\u4f2f\u6570\u5b57\u548c\u5b57\u6bcd\uff0c\u5bf9\u5176\u4ed6\u6240\u6709\u7684\u5b57\u7b26\u8fdb\u884c\u7f16\u7801\uff0c\u53ea\u8981\u8be5\u5b57\u7b26\u7684ASCII\u7801\u5c0f\u4e8e256\u3002\u7f16\u7801\u540e\u8f93\u51fa\u7684\u683c\u5f0f\u4e3a \\xHH \uff08\u4ee5 \\x \u5f00\u5934\uff0cHH\u5219\u662f\u6307\u8be5\u5b57\u7b26\u5bf9\u5e94\u7684\u5341\u516d\u8fdb\u5236\u6570\u5b57\uff09<br \/>Tips\uff1a\u8fd9\u79cd\u573a\u666f\u4ec5\u9650\u4e8e\u5916\u90e8\u6570\u636e\u62fc\u63a5\u5728js\u91cc\u88ab\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u53d8\u91cf\u503c\u4e2d\u3002\u9664\u6b64\u4e4b\u5916\u7981\u6b62\u76f4\u63a5\u5c06\u4ee3\u7801\u62fc\u63a5\u5728js\u4ee3\u7801\u4e2d\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u8f93\u51fa\u70b9\u5728CSS\u4e2d\uff08Style\u5c5e\u6027\uff09<\/td>\n<td>\u9700\u8981\u8fdb\u884cCSS\u7f16\u7801<br \/>\u7f16\u7801\u89c4\u5219\uff1a<br \/>\u9664\u4e86\u963f\u62c9\u4f2f\u6570\u5b57\u548c\u5b57\u6bcd\uff0c\u5bf9\u5176\u4ed6\u6240\u6709\u7684\u5b57\u7b26\u8fdb\u884c\u7f16\u7801\uff0c\u53ea\u8981\u8be5\u5b57\u7b26\u7684ASCII\u7801\u5c0f\u4e8e256\u3002\u7f16\u7801\u540e\u8f93\u51fa\u7684\u683c\u5f0f\u4e3a \\HH \uff08\u4ee5 \\ \u5f00\u5934\uff0cHH\u5219\u662f\u6307\u8be5\u5b57\u7b26\u5bf9\u5e94\u7684\u5341\u516d\u8fdb\u5236\u6570\u5b57\uff09<\/td>\n<\/tr>\n<tr>\n<td>\u8f93\u51fa\u70b9\u5728URL\u5c5e\u6027\u4e2d<\/td>\n<td>\u5bf9\u8fd9\u4e9b\u6570\u636e\u8fdb\u884cURL\u7f16\u7801<br \/>Tips\uff1a\u9664\u6b64\u4e4b\u5916\uff0c\u6240\u6709\u94fe\u63a5\u7c7b\u5c5e\u6027\u5e94\u8be5\u6821\u9a8c\u5176\u534f\u8bae\u3002\u7981\u6b62JavaScript\u3001data\u548cVb\u4f2a\u534f\u8bae\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>1.6.4 \u3010\u5fc5\u987b\u3011\u54cd\u5e94\u7981\u6b62\u5c55\u793a\u7269\u7406\u8d44\u6e90\u3001\u7a0b\u5e8f\u5185\u90e8\u4ee3\u7801\u903b\u8f91\u7b49\u654f\u611f\u4fe1\u606f<\/strong><\/p>\n<ul>\n<li>\u4e1a\u52a1\u751f\u4ea7\uff08\u6b63\u5f0f\uff09\u73af\u5883\uff0c\u5e94\u7528\u5f02\u5e38\u65f6\uff0c\u54cd\u5e94\u5185\u5bb9\u7981\u6b62\u5c55\u793a\u654f\u611f\u4fe1\u606f\u3002\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<code>\u7269\u7406\u8def\u5f84<\/code>\u3001<code>\u7a0b\u5e8f\u5185\u90e8\u6e90\u4ee3\u7801<\/code>\u3001<code>\u8c03\u8bd5\u65e5\u5fd7<\/code>\u3001<code>\u5185\u90e8\u8d26\u53f7\u540d<\/code>\u3001<code>\u5185\u7f51ip\u5730\u5740<\/code>\u7b49\u3002<\/li>\n<\/ul>\n<pre><code>\/\/ bad\nAccess denied for user &#039;xxx&#039;@&#039;xx.xxx.xxx.162&#039; (using password: NO)&quot;<\/code><\/pre>\n<p><strong>1.6.5 \u3010\u63a8\u8350\u3011\u6dfb\u52a0\u5b89\u5168\u7eb5\u6df1\u9632\u5fa1\u63aa\u65bd<\/strong><\/p>\n<ul>\n<li>\u90e8\u7f72CSP\uff0c\u89c4\u5219\u4e2d\u5e94\u5f15\u5165\u6700\u65b0\u7684\u4e25\u683c\u6a21\u5f0f\u7279\u6027<code>nonce-<\/code><\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ good\uff1a\u4f7f\u7528helmet\u7ec4\u4ef6\u5b89\u5168\u5730\u914d\u7f6e\u54cd\u5e94\u5934\nconst express = require(&quot;express&quot;);\nconst helmet = require(&quot;helmet&quot;);\nconst app = express();\napp.use(helmet());\n\n\/\/ good\uff1a\u6b63\u786e\u914d\u7f6eContent-Type\u3001\u6dfb\u52a0\u4e86\u5b89\u5168\u54cd\u5e94\u5934\uff0c\u5f15\u5165\u4e86CSP\nRouter.get(&quot;\/&quot;, (req, res) =&gt; {\n    res.header(&quot;Content-Type&quot;, &quot;application\/json&quot;);\n    res.header(&quot;X-Content-Type-Options&quot;, &quot;nosniff&quot;);\n    res.header(&quot;X-Frame-Options&quot;, &quot;SAMEORIGIN&quot;);\n    res.header(&quot;Content-Security-Policy&quot;, &quot;script-src &#039;self&#039;&quot;);\n});<\/code><\/pre>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u4e2d\u98ce\u9669 - XSS\u3001\u4e2d\u98ce\u9669 - \u8df3\u8f6c\u6f0f\u6d1e<\/em><\/p>\n<p><a id=\"2.1.7\"><\/a><\/p>\n<h4>1.7 \u6267\u884c\u4ee3\u7801<\/h4>\n<p><strong>1.7.1 \u3010\u5fc5\u987b\u3011\u5b89\u5168\u7684\u4ee3\u7801\u6267\u884c\u65b9\u5f0f<\/strong><\/p>\n<ul>\n<li>\u7981\u6b62\u4f7f\u7528 <code>eval<\/code> \u51fd\u6570<\/li>\n<li>\u7981\u6b62\u4f7f\u7528<code>new Function(&quot;input&quot;)()<\/code> \u6765\u521b\u5efa\u51fd\u6570<\/li>\n<li>\u4f7f\u7528 <code>setInteval<\/code>\uff0c<code>setTimeout<\/code>\uff0c\u5e94\u6821\u9a8c\u4f20\u5165\u7684\u53c2\u6570<\/li>\n<\/ul>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u9ad8\u98ce\u9669 - \u4ee3\u7801\u6267\u884c\u6f0f\u6d1e<\/em><\/p>\n<p><a id=\"2.1.8\"><\/a><\/p>\n<h4>1.8 Web\u8de8\u57df<\/h4>\n<p><strong>1.8.1 \u3010\u5fc5\u987b\u3011\u9650\u5b9aJSONP\u63a5\u53e3\u7684callback\u5b57\u7b26\u96c6\u8303\u56f4<\/strong><\/p>\n<ul>\n<li>JSONP\u63a5\u53e3\u7684callback\u51fd\u6570\u540d\u4e3a\u56fa\u5b9a\u767d\u540d\u5355\u3002\u5982callback\u51fd\u6570\u540d\u53ef\u7528\u6237\u81ea\u5b9a\u4e49\uff0c\u5e94\u9650\u5236\u51fd\u6570\u540d\u4ec5\u5305\u542b \u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u3002\u5982\uff1a<code>[a-zA-Z0-9_-]+<\/code><\/li>\n<\/ul>\n<p><strong>1.8.2 \u3010\u5fc5\u987b\u3011\u5b89\u5168\u7684CORS\u914d\u7f6e<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528CORS\uff0c\u5e94\u5bf9\u8bf7\u6c42\u5934Origin\u503c\u505a\u4e25\u683c\u8fc7\u6ee4\u3001\u6821\u9a8c\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u53ef\u4ee5\u4f7f\u7528\u201c\u5168\u7b49\u4e8e\u201d\u5224\u65ad\uff0c\u6216\u4f7f\u7528\u4e25\u683c\u7684\u6b63\u5219\u8fdb\u884c\u5224\u65ad\u3002\u5982\uff1a<code>^https:\/\/domain\\.qq\\.com$<\/code><\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ good\uff1a\u4f7f\u7528\u5168\u7b49\u4e8e\uff0c\u6821\u9a8c\u8bf7\u6c42\u7684Origin\nif (req.headers.origin === &#039;https:\/\/domain.qq.com&#039;) {\n    res.setHeader(&#039;Access-Control-Allow-Origin&#039;, req.headers.origin);\n    res.setHeader(&#039;Access-Control-Allow-Credentials&#039;, true);\n}<\/code><\/pre>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u4e2d\u98ce\u9669 - XSS\uff0c\u4e2d\u98ce\u9669 - CSRF\uff0c\u4e2d\u98ce\u9669 - CORS\u914d\u7f6e\u4e0d\u5f53<\/em><\/p>\n<p><a id=\"2.1.9\"><\/a><\/p>\n<h4>1.9 SQL\u64cd\u4f5c<\/h4>\n<p><strong>1.9.1 \u3010\u5fc5\u987b\u3011SQL\u8bed\u53e5\u9ed8\u8ba4\u4f7f\u7528\u9884\u7f16\u8bd1\u5e76\u7ed1\u5b9a\u53d8\u91cf<\/strong><\/p>\n<ul>\n<li>\n<p>\u5e94\u4f7f\u7528\u9884\u7f16\u8bd1\u7ed1\u5b9a\u53d8\u91cf\u7684\u5f62\u5f0f\u7f16\u5199sql\u8bed\u53e5\uff0c\u4fdd\u6301\u67e5\u8be2\u8bed\u53e5\u548c\u6570\u636e\u76f8\u5206\u79bb<\/p>\n<pre><code class=\"language-javascript\">\/\/ bad\uff1a\u62fc\u63a5SQL\u8bed\u53e5\u67e5\u8be2\uff0c\u5b58\u5728\u5b89\u5168\u98ce\u9669\nconst mysql  = require(\"mysql\");\nconst connection = mysql.createConnection(options);\nconnection.connect();\n\nconst sql = util.format(\"SELECT * from some_table WHERE Id = %s and Name = %s\", req.body.id, req.body.name);\nconnection.query(sql, (err, result) => {\n\/\/ handle err..\n});  \n\n\/\/ good\uff1a\u4f7f\u7528\u9884\u7f16\u8bd1\u7ed1\u5b9a\u53d8\u91cf\u6784\u9020SQL\u8bed\u53e5\nconst mysql  = require(\"mysql\");\nconst connection = mysql.createConnection(options);\nconnection.connect();\n\nconst sql = \"SELECT * from some_table WHERE Id = ? and Name = ?\";\nconst sqlParams = [req.body.id, req.body.name];\nconnection.query(sql, sqlParams, (err, result) => {\n\/\/ handle err..\n});<\/code><\/pre>\n<\/li>\n<li>\n<p>\u5bf9\u4e8e\u8868\u540d\u3001\u5217\u540d\u7b49\u65e0\u6cd5\u8fdb\u884c\u9884\u7f16\u8bd1\u7684\u573a\u666f\uff0c\u5982\uff1a<code>__user_input__<\/code> \u62fc\u63a5\u5230\u6bd4\u5982 <code>limit<\/code>, <code>order by<\/code>, <code>group by<\/code> , <code>from tablename<\/code>\u8bed\u53e5\u4e2d\u3002\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><em>\u65b9\u68481\uff1a\u4f7f\u7528\u767d\u540d\u5355\u6821\u9a8c\u8868\u540d\/\u5217\u540d<\/em><\/p>\n<pre><code class=\"language-javascript\">\/\/ good\nconst tableSuffix = req.body.type;\nif ([\"expected1\", \"expected2\"].indexOf(tableSuffix) < 0) {\n\/\/ \u4e0d\u5728\u8868\u540d\u767d\u540d\u5355\u4e2d\uff0c\u62d2\u7edd\u8bf7\u6c42\nreturn ;\n}\nconst sql = <code>SELECT * from t_business_${tableSuffix}<\/code>;\nconnection.query(sql, (err, result) => {\n\/\/ handle err..\n});<\/code><\/pre>\n<p><em>\u65b9\u68482\uff1a\u4f7f\u7528\u53cd\u5f15\u53f7\u5305\u88f9\u8868\u540d\/\u5217\u540d\uff0c\u5e76\u8fc7\u6ee4 <code>__user_input__<\/code> \u4e2d\u7684\u53cd\u5f15\u53f7<\/em><\/p>\n<pre><code class=\"language-javascript\">\/\/ good\nlet { orderType } = req.body;\n\/\/ \u8fc7\u6ee4\u6389__user_input__\u4e2d\u7684\u53cd\u5f15\u53f7\norderType = orderType.replace(\"`\", \"\");\nconst sql = util.format(\"SELECT * from t_business_feeds order by <code>%s<\/code>\", orderType);\nconnection.query(sql, (err, result) => {\n\/\/ handle err..\n});<\/code><\/pre>\n<p><em>\u65b9\u68483\uff1a\u5c06 <code>__user_input__<\/code> \u8f6c\u6362\u4e3a\u6574\u6570<\/em><\/p>\n<pre><code class=\"language-javascript\">\/\/ good\nlet { orderType } = req.body;\n\/\/ \u5f3a\u5236\u8f6c\u6362\u4e3a\u6574\u6570\norderType = parseInt(orderType, 10);\nconst sql = <code>SELECT * from t_business_feeds order by ${orderType}<\/code>;\nconnection.query(sql, (err, result) => {\n\/\/ handle err..\n});<\/code><\/pre>\n<\/li>\n<\/ul>\n<p><strong>1.9.2 \u3010\u5fc5\u987b\u3011\u5b89\u5168\u7684ORM\u64cd\u4f5c<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528\u5b89\u5168\u7684ORM\u7ec4\u4ef6\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u3002\u5982 <code>sequelize<\/code> \u7b49<\/p>\n<\/li>\n<li>\n<p>\u7981\u6b62<code>__user_input__<\/code>\u4ee5\u62fc\u63a5\u7684\u65b9\u5f0f\u76f4\u63a5\u4f20\u5165ORM\u7684\u5404\u7c7braw\u65b9\u6cd5<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/bad: adonisjs ORM\n\/\/\u53c2\u8003\uff1ahttps:\/\/adonisjs.com\/docs\/3.2\/security-introduction#_sql_injection\nconst username = request.param(&quot;username&quot;);\nconst users = yield Database\n  .table(&quot;users&quot;)\n  .where(Database.raw(`username = ${username}`));\n\n\/\/good: adonisjs ORM\nconst username = request.param(&quot;username&quot;);\nconst users = yield Database\n  .table(&#039;users&#039;)\n  .where(Database.raw(&quot;username = ?&quot;, [username]));<\/code><\/pre>\n<ul>\n<li>\u4f7f\u7528ORM\u8fdb\u884cUpdate\/Insert\u64cd\u4f5c\u65f6\uff0c\u5e94\u9650\u5236\u64cd\u4f5c\u5b57\u6bb5\u8303\u56f4<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/*\ngood\n\u5047\u8bbe\u8be5api\u7528\u4e8e\u63d2\u5165\u7528\u6237\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u4f7f\u7528\u4f20\u5165\u7684req.body\u901a\u8fc7Sequelize\u7684create\u65b9\u6cd5\u5b9e\u73b0\n\u5047\u8bbeUser\u5305\u542b\u5b57\u6bb5\uff1ausername,email,isAdmin\uff0c\n\u5176\u4e2d,isAdmin\u5c06\u4f1a\u7528\u4e8e\u662f\u5426\u7cfb\u7edf\u7ba1\u7406\u5458\u7684\u9274\u6743\uff0c\u9ed8\u8ba4\u503c\u4e3afalse\n*\/\n\/\/ Sequelize: \u53ea\u5141\u8bb8\u53d8\u66f4username\u3001email\u5b57\u6bb5\u503c\nUser.create(req.body, { fields: [&quot;username&quot;, &quot;email&quot;] }).then((user) =&gt; {\n    \/\/ handle the rest..\n});<\/code><\/pre>\n<blockquote>\n<p><strong>\u4e3a\u4ec0\u4e48\u8981\u8fd9\u4e48\u505a\uff1f<\/strong><br \/>\n\u5728\u4e0a\u8ff0\u6848\u4f8b\u4e2d\uff0c\u82e5\u4e0d\u9650\u5b9afields\u503c\uff0c\u653b\u51fb\u8005\u5c06\u53ef\u4f20\u5165<code>{&quot;username&quot;:&quot;boo&quot;,&quot;email&quot;:&quot;foo@boo.com&quot;,&quot;isAdmin&quot;:true}<\/code>\u5c06\u81ea\u5df1\u53d8\u4e3a<code>Admin<\/code>\uff0c\u4ea7\u751f\u5782\u76f4\u8d8a\u6743\u6f0f\u6d1e\u3002<\/p>\n<\/blockquote>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u9ad8\u98ce\u9669 - SQL\u6ce8\u5165\uff0c\u4e2d\u98ce\u9669 - Mass Assignment \u903b\u8f91\u6f0f\u6d1e<\/em><\/p>\n<p><a id=\"2.1.10\"><\/a><\/p>\n<h4>1.10 NoSQL\u64cd\u4f5c<\/h4>\n<p><strong>1.10.1 \u3010\u5fc5\u987b\u3011\u6821\u9a8c\u53c2\u6570\u503c\u7c7b\u578b<\/strong><\/p>\n<ul>\n<li>\u5c06HTTP\u53c2\u6570\u503c\u4ee3\u5165NoSQL\u64cd\u4f5c\u524d\uff0c\u5e94\u6821\u9a8c\u7c7b\u578b\u3002\u5982\u975e\u529f\u80fd\u9700\u8981\uff0c\u7981\u6b62\u5bf9\u8c61\uff08Object\uff09\u7c7b\u578b\u4f20\u5165\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ bad\uff1a\u6267\u884cNOSQL\u64cd\u4f5c\u524d\uff0c\u672a\u4f5c\u4efb\u4f55\u5224\u65ad\napp.post(&quot;\/&quot;, (req, res) =&gt; {\n    db.users.find({ username: req.body.username, password: req.body.password }, (err, users) =&gt; {\n    \/\/ **TODO:** handle the rest\n    });\n});\n\n\/\/ good\uff1a\u5728\u8fdb\u5165nosql\u524d\u5148\u5224\u65ad`__USER_INPUT__`\u662f\u5426\u4e3a\u5b57\u7b26\u4e32\u3002\napp.post(&quot;\/&quot;, (req, res) =&gt; {\n    if (req.body.username &amp;&amp; typeof req.body.username !== &quot;string&quot;) {\n        return new Error(&quot;username must be a string&quot;);\n    }\n    if (req.body.password &amp;&amp; typeof req.body.password !== &quot;string&quot;) {\n        return new Error(&quot;password must be a string&quot;);\n    }\n    db.users.find({ username: req.body.username, password: req.body.password }, (err, users) =&gt; {\n        \/\/ **TODO:** handle the rest\n    });\n});<\/code><\/pre>\n<blockquote>\n<p><strong>\u4e3a\u4ec0\u4e48\u8981\u8fd9\u4e48\u505a\uff1f<\/strong><\/p>\n<p>JavaScript\u4e2d\uff0c\u4ecehttp\u6216socket\u63a5\u6536\u7684\u6570\u636e\u53ef\u80fd\u4e0d\u662f\u5355\u7eaf\u7684\u5b57\u7b26\u4e32\uff0c\u800c\u662f\u88ab\u9ed1\u5ba2\u7cbe\u5fc3\u6784\u9020\u7684\u5bf9\u8c61(Object)\u3002\u5728\u672c\u4f8b\u4e2d\uff1a<\/p>\n<ul>\n<li>\u671f\u671b\u63a5\u6536\u7684POST\u6570\u636e\uff1a<code>username=foo&amp;password=bar<\/code> <\/li>\n<li>\u671f\u671b\u7684\u7b49\u4ef7\u6761\u4ef6\u67e5\u8be2sql\u8bed\u53e5\uff1a<code>select * from users where username = &#039;foo&#039; and password = &#039;bar&#039;<\/code><\/li>\n<li>\u9ed1\u5ba2\u7684\u7cbe\u5fc3\u6784\u9020\u7684\u653b\u51fbPOST\u6570\u636e\uff1a<code>username[$ne]=null&amp;password[$ne]=null<\/code>\u6216JSON\u683c\u5f0f\uff1a<code>{&quot;username&quot;: {&quot;$ne&quot;: null},&quot;password&quot;: {&quot;$ne&quot;: null}}<\/code><\/li>\n<li>\u9ed1\u5ba2\u7be1\u6539\u540e\u7684\u7b49\u4ef7\u6761\u4ef6\u67e5\u8be2sql\u8bed\u53e5\uff1a<code>select * from users where username != null &amp; password != null<\/code><\/li>\n<li>\u9ed1\u5ba2\u653b\u51fb\u7ed3\u679c\uff1a\u7ed5\u8fc7\u6b63\u5e38\u903b\u8f91\uff0c\u5728\u4e0d\u77e5\u9053\u4ed6\u4eba\u7684username\/password\u7684\u60c5\u51b5\u767b\u5f55\u4ed6\u4eba\u8d26\u53f7\u3002<\/li>\n<\/ul>\n<\/blockquote>\n<p><strong>1.10.2 \u3010\u5fc5\u987b\u3011NoSQL\u64cd\u4f5c\u524d\uff0c\u5e94\u6821\u9a8c\u6743\u9650\/\u89d2\u8272<\/strong><\/p>\n<ul>\n<li>\u6267\u884cNoSQL\u589e\u3001\u5220\u3001\u6539\u3001\u67e5\u903b\u8f91\u524d\uff0c\u5e94\u6821\u9a8c\u6743\u9650<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ \u4f7f\u7528express\u3001mongodb(mongoose)\u5b9e\u73b0\u7684\u5220\u9664\u6587\u7ae0demo\n\/\/ bad\uff1a\u5728\u5220\u9664\u6587\u7ae0\u524d\u672a\u505a\u6743\u9650\u6821\u9a8c\napp.post(&quot;\/deleteArticle&quot;, (req, res) =&gt; {\n    db.articles.deleteOne({ article_id: req.body.article_id }, (err, users) =&gt; {\n        \/\/ TODO: handle the rest\n    });\n});\n\n\/\/ good\uff1a\u8fdb\u5165nosql\u8bed\u53e5\u524d\u5148\u8fdb\u884c\u6743\u9650\u6821\u9a8c\napp.post(&quot;\/deleteArticle&quot;, (req, res) =&gt; {\n    checkPriviledge(ctx.uin, req.body.article_id);\n    db.articles.deleteOne({ article_id: req.body.article_id }, (err, users) =&gt; {\n        \/\/ TODO: handle the rest\n    });\n});<\/code><\/pre>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u9ad8\u98ce\u9669 - \u8d8a\u6743\u64cd\u4f5c\uff0c\u9ad8\u98ce\u9669 - NoSQL\u6ce8\u5165<\/em><\/p>\n<p><a id=\"2.1.11\"><\/a><\/p>\n<h4>1.11 \u670d\u52a1\u5668\u7aef\u6e32\u67d3\uff08SSR\uff09<\/h4>\n<p><strong>1.11.1 \u3010\u5fc5\u987b\u3011\u5b89\u5168\u7684Vue\u670d\u52a1\u5668\u7aef\u6e32\u67d3(Vue SSR)<\/strong><\/p>\n<ul>\n<li>\n<p>\u7981\u6b62\u76f4\u63a5\u5c06\u4e0d\u53d7\u4fe1\u7684\u5916\u90e8\u5185\u5bb9\u4f20\u5165<code>{{{ data }}}<\/code>\u8868\u8fbe\u5f0f\u4e2d<\/p>\n<\/li>\n<li>\n<p>\u6a21\u677f\u5185\u5bb9\u7981\u6b62\u88ab\u6c61\u67d3<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ bad: \u5c06\u7528\u6237\u8f93\u5165\u66ff\u6362\u8fdb\u6a21\u677f\nconst app = new Vue({\n    template: appTemplate.replace(&quot;word&quot;, __USER_INPUT__),\n});\nrenderer.renderToString(app);<\/code><\/pre>\n<ul>\n<li>\u5bf9\u5df2\u6e32\u67d3\u7684HTML\u6587\u672c\u5185\u5bb9\uff08renderToString\u540e\u7684html\u5185\u5bb9\uff09\u3002\u5982\u9700\u518d\u62fc\u4e0d\u53d7\u4fe1\u7684\u5916\u90e8\u8f93\u5165\uff0c\u5e94\u5148\u8fdb\u884c\u5b89\u5168\u8fc7\u6ee4\uff0c\u5177\u4f53\u8bf7\u53c2\u8003<strong>1.6.3<\/strong><\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ bad: \u6e32\u67d3\u540e\u7684html\u518d\u62fc\u63a5\u4e0d\u53d7\u4fe1\u7684\u5916\u90e8\u8f93\u5165\nreturn new Promise(((resolve) =&gt; {\n    renderer.renderToString(component, (err, html) =&gt; {\n        let htmlOutput = html;\n        htmlOutput += `${__USER_INPUT__}`;\n        resolve(htmlOutput);\n    });\n}));<\/code><\/pre>\n<p><strong>1.11.2 \u3010\u5fc5\u987b\u3011\u5b89\u5168\u5730\u4f7f\u7528EJS\u3001LoDash\u3001UnderScore\u8fdb\u884c\u670d\u52a1\u5668\u7aef\u6e32\u67d3<\/strong><\/p>\n<ul>\n<li>\n<p>\u4f7f\u7528render\u51fd\u6570\u65f6\uff0c\u6a21\u677f\u5185\u5bb9\u7981\u6b62\u88ab\u6c61\u67d3<\/p>\n<p>lodash.Template:<\/p>\n<pre><code class=\"language-js\">\/\/ bad: \u5c06\u7528\u6237\u8f93\u5165\u9001\u8fdb\u6a21\u677f\nconst compiled = _.template(<code>&lt;b&gt;${__USER_INPUT__}&lt;%- value %&gt;&lt;\/b&gt;<\/code>);\ncompiled({ value: \"hello\" });<\/code><\/pre>\n<p>ejs:<\/p>\n<pre><code class=\"language-javascript\">\/\/ bad: \u5c06\u7528\u6237\u8f93\u5165\u9001\u8fdb\u6a21\u677f\nconst ejs = require(\"ejs\");\nconst people = [\"geddy\", \"neil\", \"alex\"];\nconst html = ejs.render(<code>&lt;%= people.join(&quot;, &quot;); %&gt;${__USER_INPUT__}<\/code>, { people });<\/code><\/pre>\n<\/li>\n<li>\n<p>Ejs\u3001LoDash\u3001UnderScore\u63d0\u4f9b\u7684HTML\u63d2\u503c\u6a21\u677f\u9ed8\u8ba4\u5f62\u4f3c<code>&lt;%= data %&gt;<\/code>\uff0c\u5c3d\u7ba1\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b<code>&lt;%= data %&gt;<\/code>\u5b58\u5728\u8fc7\u6ee4\uff0c\u5728\u7f16\u5199HTML\u63d2\u503c\u6a21\u677f\u65f6\u9700\u6ce8\u610f:<\/p>\n<ol>\n<li>\u7528\u6237\u8f93\u5165\u6d41\u5165html\u5c5e\u6027\u503c\u65f6\uff0c\u5fc5\u987b\u4f7f\u7528\u53cc\u5f15\u53f7\u5305\u88f9\uff1a<code>&lt;base data-id = &quot;&lt;%= __USER_INPUT__ %&gt;&quot;&gt;<\/code><\/li>\n<li>\u7528\u6237\u8f93\u5165\u6d41\u5165<code>&lt;script&gt;&lt;\/script&gt;<\/code>\u6807\u7b7e\u6216on*\u7684html\u5c5e\u6027\u4e2d\u65f6\uff0c\u5982<code>&lt;script&gt;var id = &lt;%= __USER_INPUT__ %&gt;&lt;\/script&gt;<\/code> \uff0c\u987b\u6309\u71671.6.3\u4e2d\u7684\u505a\u6cd5\u6216\u767d\u540d\u5355\u65b9\u6cd5\u8fdb\u884c\u8fc7\u6ee4\uff0c\u6846\u67b6\/\u7ec4\u4ef6\u7684\u8fc7\u6ee4\u5728\u6b64\u5904\u4e0d\u8d77\u4f5c\u7528<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p><strong>1.11.3 \u3010\u5fc5\u987b\u3011\u5728\u81ea\u884c\u5b9e\u73b0\u72b6\u6001\u5b58\u50a8\u5bb9\u5668\u5e76\u5c06\u5176JSON.Stringify\u5e8f\u5217\u5316\u540e\u6ce8\u5165\u5230HTML\u65f6\uff0c\u5fc5\u987b\u8fdb\u884c\u5b89\u5168\u8fc7\u6ee4<\/strong><\/p>\n<p><a id=\"2.1.12\"><\/a><\/p>\n<h4>1.12 URL\u8df3\u8f6c<\/h4>\n<p><strong>1.12.1\u3010\u5fc5\u987b\u3011\u9650\u5b9a\u8df3\u8f6c\u76ee\u6807\u5730\u5740<\/strong><\/p>\n<ul>\n<li>\u9002\u7528\u573a\u666f\u5305\u62ec\uff1a<\/li>\n<\/ul>\n<ol>\n<li>\u4f7f\u752830x\u8fd4\u56de\u7801\u5e76\u5728Header\u4e2d\u8bbe\u7f6eLocation\u8fdb\u884c\u8df3\u8f6c<\/li>\n<li>\u5728\u8fd4\u56de\u9875\u9762\u4e2d\u6253\u5370<code>&lt;script&gt;location.href=__Redirection_URL__&lt;\/script&gt;<\/code><\/li>\n<\/ol>\n<ul>\n<li>\u4f7f\u7528\u767d\u540d\u5355\uff0c\u9650\u5b9a\u91cd\u5b9a\u5411\u5730\u5740\u7684\u534f\u8bae\u524d\u7f00\uff08\u9ed8\u8ba4\u53ea\u5141\u8bb8HTTP\u3001HTTPS\uff09\u3001\u57df\u540d\uff08\u9ed8\u8ba4\u53ea\u5141\u8bb8\u516c\u53f8\u6839\u57df\uff09\uff0c\u6216\u6307\u5b9a\u4e3a\u56fa\u5b9a\u503c\uff1b<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">\/\/ \u4f7f\u7528express\u5b9e\u73b0\u7684\u767b\u5f55\u6210\u529f\u540e\u7684\u56de\u8c03\u8df3\u8f6c\u9875\u9762\n\n\/\/ bad: \u672a\u6821\u9a8c\u9875\u9762\u91cd\u5b9a\u5411\u5730\u5740\napp.get(&quot;\/login&quot;, (req, res) =&gt; {\n    \/\/ \u82e5\u672a\u767b\u5f55\u7528\u6237\u8bbf\u95ee\u5176\u4ed6\u9875\u9762\uff0c\u5219\u8ba9\u7528\u6237\u5bfc\u5411\u5230\u8be5\u5904\u7406\u51fd\u6570\u8fdb\u884c\u767b\u5f55\n  \/\/ \u4f7f\u7528\u53c2\u6570loginCallbackUrl\u8bb0\u5f55\u5148\u524d\u5c1d\u8bd5\u8bbf\u95ee\u7684url\uff0c\u5728\u767b\u5f55\u6210\u529f\u540e\u8df3\u8f6c\u56deloginCallbackUrl:\n    const { loginCallbackUrl } = req.query;\n    if (loginCallbackUrl) {\n        res.redirect(loginCallbackUrl);\n    }\n});\n\n\/\/ good: \u767d\u540d\u5355\u9650\u5b9a\u91cd\u5b9a\u5411\u5730\u5740\nfunction isValidURL(sUrl) {\n    return !!((\/^(https?:\\\/\\\/)?[\\w\\-.]+\\.(qq|tencent)\\.com($|\\\/|\\\\)\/i).test(sUrl) || (\/^[\\w][\\w\/.\\-_%]+$\/i).test(sUrl) || (\/^[\/\\\\][^\/\\\\]\/i).test(sUrl));\n}\napp.get(&quot;\/login&quot;, (req, res) =&gt; {\n    \/\/ \u82e5\u672a\u767b\u5f55\u7528\u6237\u8bbf\u95ee\u5176\u4ed6\u9875\u9762\uff0c\u5219\u8ba9\u7528\u6237\u5bfc\u5411\u5230\u8be5\u5904\u7406\u51fd\u6570\u8fdb\u884c\u767b\u5f55\n  \/\/ \u4f7f\u7528\u53c2\u6570loginCallbackUrl\u8bb0\u5f55\u5148\u524d\u5c1d\u8bd5\u8bbf\u95ee\u7684url\uff0c\u5728\u767b\u5f55\u6210\u529f\u540e\u8df3\u8f6c\u56deloginCallbackUrl:\n    const { loginCallbackUrl } = req.query;\n    if (loginCallbackUrl &amp;&amp; isValidUrl(loginCallbackUrl)) {\n        res.redirect(loginCallbackUrl);\n    }\n});\n\n\/\/ good: \u767d\u540d\u5355\u9650\u5b9a\u91cd\u5b9a\u5411\u5730\u5740\uff0c\u901a\u8fc7\u8fd4\u56dehtml\u5b9e\u73b0\nfunction isValidURL(sUrl) {\n    return !!((\/^(https?:\\\/\\\/)?[\\w\\-.]+\\.(qq|tencent)\\.com($|\\\/|\\\\)\/i).test(sUrl) || (\/^[\\w][\\w\/.\\-_%]+$\/i).test(sUrl) || (\/^[\/\\\\][^\/\\\\]\/i).test(sUrl));\n}\napp.get(&quot;\/login&quot;, (req, res) =&gt; {\n    \/\/ \u82e5\u672a\u767b\u5f55\u7528\u6237\u8bbf\u95ee\u5176\u4ed6\u9875\u9762\uff0c\u5219\u8ba9\u7528\u6237\u5bfc\u5411\u5230\u8be5\u5904\u7406\u51fd\u6570\u8fdb\u884c\u767b\u5f55\n  \/\/ \u4f7f\u7528\u53c2\u6570loginCallbackUrl\u8bb0\u5f55\u5148\u524d\u5c1d\u8bd5\u8bbf\u95ee\u7684url\uff0c\u5728\u767b\u5f55\u6210\u529f\u540e\u8df3\u8f6c\u56deloginCallbackUrl:\n    const { loginCallbackUrl } = req.query;\n    if (loginCallbackUrl &amp;&amp; isValidUrl(loginCallbackUrl)) {\n        \/\/ \u4f7f\u7528encodeURI\uff0c\u8fc7\u6ee4\u5de6\u53f3\u5c16\u62ec\u53f7\u4e0e\u53cc\u5f15\u53f7\uff0c\u9632\u6b62\u9003\u9038\u51fa\u5305\u88f9\u7684\u53cc\u5f15\u53f7\n        const redirectHtml = `&lt;script&gt;location.href = &quot;${encodeURI(loginCallbackUrl)}&quot;;&lt;\/script&gt;`;\n        res.end(redirectHtml);\n    }\n});<\/code><\/pre>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u4e2d\u98ce\u9669 - \u4efb\u610fURL\u8df3\u8f6c\u6f0f\u6d1e<\/em><\/p>\n<p><a id=\"2.1.13\"><\/a><\/p>\n<h4>1.13 Cookie\u4e0e\u767b\u5f55\u6001<\/h4>\n<p><strong>1.13.1\u3010\u63a8\u8350\u3011\u4e3aCookies\u4e2d\u5b58\u50a8\u7684\u5173\u952e\u767b\u5f55\u6001\u4fe1\u606f\u6dfb\u52a0http-only\u4fdd\u62a4<\/strong><\/p>\n<p><em>\u5173\u8054\u6f0f\u6d1e\uff1a\u7eb5\u6df1\u9632\u62a4\u63aa\u65bd - \u5b89\u5168\u6027\u589e\u5f3a\u7279\u6027<\/em><\/p>\n<p><a id=\"2.2\"><\/a><\/p>\n<h3>II. \u914d\u7f6e&amp;\u73af\u5883<\/h3>\n<p><a id=\"2.2.1\"><\/a><\/p>\n<h4>2.1 \u4f9d\u8d56\u5e93<\/h4>\n<p><strong>2.1.1\u3010\u5fc5\u987b\u3011\u4f7f\u7528\u5b89\u5168\u7684\u4f9d\u8d56\u5e93<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u81ea\u52a8\u5de5\u5177\uff0c\u68c0\u67e5\u4f9d\u8d56\u5e93\u662f\u5426\u5b58\u5728\u540e\u95e8\/\u6f0f\u6d1e\uff0c\u4fdd\u6301\u6700\u65b0\u7248\u672c<\/li>\n<\/ul>\n<p><a id=\"2.2.2\"><\/a><\/p>\n<h4>2.2 \u8fd0\u884c\u73af\u5883<\/h4>\n<p><strong>2.2.1 \u3010\u5fc5\u987b\u3011\u4f7f\u7528\u975eroot\u7528\u6237\u8fd0\u884cNode.js<\/strong><\/p>\n<p><a id=\"2.2.3\"><\/a><\/p>\n<h4>2.3 \u914d\u7f6e\u4fe1\u606f<\/h4>\n<p><strong>2.3.1\u3010\u5fc5\u987b\u3011\u7981\u6b62\u786c\u7f16\u7801\u8ba4\u8bc1\u51ed\u8bc1<\/strong><\/p>\n<ul>\n<li>\u7981\u6b62\u5728\u6e90\u7801\u4e2d\u786c\u7f16\u7801<code>AK\/SK<\/code>\u3001<code>\u6570\u636e\u5e93\u8d26\u5bc6<\/code>\u3001<code>\u79c1\u94a5\u8bc1\u4e66<\/code>\u7b49\u914d\u7f6e\u4fe1\u606f<\/li>\n<li>\u5e94\u4f7f\u7528\u914d\u7f6e\u7cfb\u7edf\u6216KMS\u5bc6\u94a5\u7ba1\u7406\u7cfb\u7edf\u3002<\/li>\n<\/ul>\n<p><strong>2.3.2\u3010\u5fc5\u987b\u3011\u7981\u6b62\u786c\u7f16\u7801IP\u914d\u7f6e<\/strong><\/p>\n<ul>\n<li>\u7981\u6b62\u5728\u6e90\u7801\u4e2d\u786c\u7f16\u7801<code>IP<\/code>\u4fe1\u606f<\/li>\n<\/ul>\n<blockquote>\n<p><strong>\u4e3a\u4ec0\u4e48\u8981\u8fd9\u4e48\u505a\uff1f<\/strong><\/p>\n<p>\u786c\u7f16\u7801IP\u53ef\u80fd\u4f1a\u5bfc\u81f4\u540e\u7eed\u673a\u5668\u88c1\u64a4\u6216\u53d8\u66f4\u65f6\u4ea7\u751f\u989d\u5916\u7684\u5de5\u4f5c\u91cf\uff0c\u5f71\u54cd\u7cfb\u7edf\u7684\u53ef\u9760\u6027\u3002<\/p>\n<\/blockquote>\n<p><strong>2.3.3\u3010\u5fc5\u987b\u3011\u7981\u6b62\u786c\u7f16\u7801\u5458\u5de5\u654f\u611f\u4fe1\u606f<\/strong><\/p>\n<ul>\n<li>\u7981\u6b62\u5728\u6e90\u4ee3\u7801\u4e2d\u542b\u5458\u5de5\u654f\u611f\u4fe1\u606f\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\uff1a<code>\u5458\u5de5ID<\/code>\u3001<code>\u624b\u673a\u53f7<\/code>\u3001<code>\u5fae\u4fe1\/QQ\u53f7<\/code>\u7b49\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript\u9875\u9762\u7c7b I. \u4ee3\u7801\u5b9e\u73b0 1.1 \u539f\u751fDOM API\u7684\u5b89\u5168\u64cd\u4f5c 1.1.1\u3010\u5fc5\u987b\u3011HTML\u6807\u7b7e\u64cd\u4f5c\uff0c\u9650\u5b9a\/\u8fc7\u6ee4\u4f20\u5165\u53d8\u91cf   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[150],"tags":[],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/2025"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2025"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/2025\/revisions"}],"predecessor-version":[{"id":2026,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/2025\/revisions\/2026"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2025"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}