{"id":74070,"date":"2024-02-26T13:48:41","date_gmt":"2024-02-26T05:48:41","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=74070"},"modified":"2024-02-26T13:48:54","modified_gmt":"2024-02-26T05:48:54","slug":"php%e6%a1%86%e6%9e%b6%e7%9a%84%e5%ae%89%e5%85%a8%e6%80%a7%e6%af%94%e8%be%83","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/74070.html","title":{"rendered":"PHP\u6846\u67b6\u7684\u5b89\u5168\u6027\u6bd4\u8f83"},"content":{"rendered":"<p style=\"text-align:center;\" ><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-74071\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/02\/img-86sdHEUOmJmWcP5pPIOzr02a.png?x-oss-process=image\/auto-orient,1\/format,webp\" width=\"600\" height=\"342\" alt=\"PHP\u6846\u67b6\u7684\u5b89\u5168\u6027\u6bd4\u8f83\" \/><\/p>\n<p>\u5728\u8ba8\u8bbaPHP\u6846\u67b6\u7684\u5b89\u5168\u6027\u6bd4\u8f83\u65f6\uff0c<strong>Laravel\u3001Symfony\u3001CodeIgniter\u3001Yii<\/strong>\u548c<strong>CakePHP<\/strong>\u662f\u5e38\u88ab\u63d0\u53ca\u7684\u51e0\u4e2a\u540d\u5b57\u3002\u5728\u5b89\u5168\u6027\u65b9\u9762\uff0c\u5404\u6709\u4f18\u7f3a\u70b9\u3002<strong>Laravel<\/strong>\u5177\u6709\u5f3a\u5927\u7684\u5b89\u5168\u4fdd\u969c\uff0c\u5176\u4e2d\u5185\u7f6e\u4e86\u4f17\u591a\u5b89\u5168\u7279\u6027\uff0c\u5982CSRF\u4fdd\u62a4\u3001SQL\u6ce8\u5165\u9632\u62a4\u3001\u5bc6\u7801\u54c8\u5e0c\u7b49\u3002\u4e0e\u6b64\u540c\u65f6\uff0c<strong>Symfony<\/strong>\u4e5f\u5177\u6709\u8f83\u5f3a\u7684\u5b89\u5168\u7279\u6027\uff0c\u5e76\u4e14\u4e0eLaravel\u76f8\u6bd4\uff0c\u66f4\u52a0\u9002\u5e94\u5927\u578b\u5e94\u7528\u7684\u5f00\u53d1\u3002\u800c<strong>CodeIgniter\u3001Yii\u548cCakePHP<\/strong>\u5728\u5b89\u5168\u6574\u5408\u65b9\u9762\u5e76\u65e0\u663e\u8457\u5dee\u5f02\uff0c\u4f46\u5728\u793e\u533a\u548c\u6587\u6863\u652f\u6301\u65b9\u9762\u6709\u6240\u533a\u522b\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u6bd4\u8f83\u8fd9\u4e9b\u6846\u67b6\u5728\u5b89\u5168\u6027\u4e0a\u7684\u5dee\u5f02\u3002<\/p>\n<h2><strong>\u4e00\u3001LARAVEL\u6846\u67b6<\/strong><\/h2>\n<p>Laravel\u6846\u67b6\u88ab\u5e7f\u6cdb\u8ba4\u4e3a\u662f\u5177\u6709\u6700\u597d\u9884\u9632\u63aa\u65bd\u7684PHP\u6846\u67b6\u4e4b\u4e00\u3002Laravel\u7684\u4e3b\u8981\u5b89\u5168\u7279\u6027\u5305\u62ec<strong>CSRF\u4fdd\u62a4\u3001SQL\u6ce8\u5165\u9632\u62a4\u3001\u5bc6\u7801\u54c8\u5e0c\u7b49<\/strong>\u3002<\/p>\n<p>1. CSRF\u4fdd\u62a4\u3002<\/p>\n<p>Laravel\u6846\u67b6\u7684CSRF\u4fdd\u62a4\u80fd\u591f\u6709\u6548\u9632\u6b62\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020\u653b\u51fb\u3002Laravel\u6846\u67b6\u901a\u8fc7\u751f\u6210\u5e76\u9a8c\u8bc1CSRF\u4ee4\u724c\uff0c\u6765\u786e\u4fdd\u53ea\u6709\u751f\u6210\u8be5\u8bf7\u6c42\u7684\u7f51\u7ad9\u624d\u80fd\u54cd\u5e94\u76f8\u5e94\u8bf7\u6c42\u3002\u8fd9\u79cd\u9632\u62a4\u65b9\u5f0f\u80fd\u5927\u5927\u589e\u52a0\u653b\u51fb\u8005\u5b8c\u6210CSRF\u653b\u51fb\u7684\u96be\u5ea6\u3002<\/p>\n<p>2. SQL\u6ce8\u5165\u9632\u62a4\u3002<\/p>\n<p>\u5728\u4fdd\u62a4\u6570\u636e\u5e93\u5b89\u5168\u65b9\u9762\uff0cLaravel\u4e5f\u505a\u5f97\u5f88\u597d\u3002\u5176\u4f7f\u7528PDO\u7ed1\u5b9a\u53c2\u6570\u6765\u9632\u6b62SQL\u6ce8\u5165\u3002\u6b64\u5916\uff0cLaravel\u7684Eloquent ORM\u53ef\u4ee5\u8ba9\u5f00\u53d1\u8005\u6784\u5efa\u67e5\u8be2\u8bed\u53e5\uff0c\u800c\u65e0\u9700\u5199\u51fa\u4e00\u884cSQL\uff0c\u4e5f\u80fd\u786e\u4fddSQL\u7684\u5b89\u5168\u3002<\/p>\n<h2><strong>\u4e8c\u3001SYMFONY\u6846\u67b6<\/strong><\/h2>\n<p>Symfony\u4ea6\u662f\u4e00\u4e2a\u5b89\u5168\u6027\u8f83\u9ad8\u7684PHP\u6846\u67b6\u3002Symfony\u63d0\u4f9b\u4e86\u4e00\u6574\u5957\u5b89\u5168\u7ec4\u4ef6\uff0c\u5982<strong>HTTP\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u3001\u8ba4\u8bc1\u548c\u6388\u6743\u3001\u7528\u6237\u89d2\u8272\u7ba1\u7406\u3001\u5b89\u5168\u914d\u7f6e<\/strong>\u7b49\u3002<\/p>\n<p>1. HTTP\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u3002<\/p>\n<p>Symfony\u6846\u67b6\u53ef\u4ee5\u4f7f\u7528HTTP\u57fa\u672c\u8eab\u4efd\u9a8c\u8bc1\u65b9\u5f0f\uff0c\u5b83\u901a\u8fc7\u7528\u6237\u540d\u548c\u5bc6\u7801\u5bf9\u7528\u6237\u8fdb\u884c\u9a8c\u8bc1\u3002\u867d\u7136\u8fd9\u79cd\u65b9\u5f0f\u5e76\u975e\u6700\u5b89\u5168\uff0c\u4f46\u5374\u5f88\u5bb9\u6613\u5b9e\u73b0\uff0c\u5e76\u4e14Symfony\u4e5f\u63d0\u4f9b\u4e86\u66f4\u5b89\u5168\u7684HTTP\u6458\u8981\u8ba4\u8bc1\u65b9\u5f0f\u3002<\/p>\n<p>2. \u5b89\u5168\u914d\u7f6e\u3002<\/p>\n<p>\u5728Symfony\u4e2d\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u914d\u7f6e\u5b89\u5168\u9009\u9879\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u9009\u62e9\u542f\u7528\u6216\u7981\u7528\u5b89\u5168\u7ec4\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5b9a\u4e49\u8bbf\u95ee\u63a7\u5236\u89c4\u5219\u3002<\/p>\n<h2><strong>\u4e09\u3001CODEIGNITER\u6846\u67b6<\/strong><\/h2>\n<p>CodeIgniter\u7684\u5b89\u5168\u6027\u5f97\u76ca\u4e8e\u5b83\u7684\u8f7b\u91cf\u6027\uff0c\u5b83\u63d0\u4f9b\u4e86\u57fa\u672c\u7684\u9884\u9632\u63aa\u65bd\uff0c\u5982<strong>XSS\u8fc7\u6ee4\u3001SQL\u6ce8\u5165\u9632\u62a4<\/strong>\u3002<\/p>\n<p>1. XSS\u8fc7\u6ee4<\/p>\n<p>CodeIgniter\u63d0\u4f9b\u4e86XSS\u6e05\u7406\u51fd\u6570\uff0c\u53ef\u4ee5\u4e3a\u8f93\u5165\u6570\u636e\u8fdb\u884cXSS\u8fc7\u6ee4\u3002\u5f00\u53d1\u8005\u4e5f\u53ef\u4ee5\u542f\u7528XSS\u8fc7\u6ee4\u5168\u5c40\u914d\u7f6e\uff0c\u4f7f\u6240\u6709\u7684GET\u3001POST\u3001COOKIE\u6570\u636e\u90fd\u7ecf\u8fc7XSS\u8fc7\u6ee4\u3002<\/p>\n<p>2. SQL \u6ce8\u5165\u9632\u62a4<\/p>\n<p>CodeIgniter\u4f7f\u7528\u67e5\u8be2\u7ed1\u5b9a\u6765\u5b9e\u73b0SQL\u6ce8\u5165\u9632\u62a4\uff0c\u5b83\u4f1a\u81ea\u52a8\u628a\u8f93\u5165\u6570\u636e\u8fdb\u884c\u8f6c\u4e49\uff0c\u4ece\u800c\u9632\u6b62SQL\u6ce8\u5165\u653b\u51fb\u3002<\/p>\n<h2><strong>\u56db\u3001YII\u548cCAKEPHP\u6846\u67b6<\/strong><\/h2>\n<p>Yii\u548cCakePHP\u6846\u67b6\u5728\u5b89\u5168\u6027\u4e0a\u8868\u73b0\u76f8\u8fd1\u3002\u5b83\u4eec\u90fd\u63d0\u4f9b\u4e86\u57fa\u672c\u7684\u5b89\u5168\u4fdd\u62a4\uff0c\u5982<strong>CSRF\u4fdd\u62a4\u3001XSS\u9632\u62a4\u3001\u8f93\u5165\u9a8c\u8bc1\u548c\u8fc7\u6ee4<\/strong>\u3002<\/p>\n<p>1. CSRF\u4fdd\u62a4\u3002<\/p>\n<p>Yii\u548cCakePHP\u90fd\u5185\u7f6e\u4e86CSRF\u4fdd\u62a4\u529f\u80fd\uff0c\u80fd\u9632\u6b62\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020\u653b\u51fb\u3002\u8fd9\u4e24\u4e2a\u6846\u67b6\u90fd\u4f7f\u7528\u4e86\u9690\u85cf\u8868\u5355\u6765\u5b9e\u73b0CSRF\u4fdd\u62a4\u3002<\/p>\n<p>2. XSS\u9632\u62a4\u548c\u8f93\u5165\u9a8c\u8bc1\u3002<\/p>\n<p>Yii\u548cCakePHP\u6846\u67b6\u4e5f\u63d0\u4f9b\u4e86XSS\u9632\u62a4\u529f\u80fd\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u4e24\u4e2a\u6846\u67b6\u90fd\u53ef\u8fdb\u884c\u8868\u5355\u9a8c\u8bc1\u548c\u6570\u636e\u8fc7\u6ee4\u3002<\/p>\n<h2><strong>\u4e94\u3001\u603b\u7ed3<\/strong><\/h2>\n<p>\u6bcf\u4e2aPHP\u6846\u67b6\u5728\u5b89\u5168\u6027\u4e0a\u90fd\u6709\u81ea\u5df1\u7684\u4f18\u70b9\u3002\u603b\u7684\u6765\u8bf4\uff0cLaravel\u7efc\u5408\u5b89\u5168\u6027\u6700\u9ad8\uff0cSymfony\u9002\u5408\u5904\u7406\u5927\u578b\u5e94\u7528\u7684\u5b89\u5168\u95ee\u9898\uff0c\u800cCodeIgniter\u56e0\u5176\u8f7b\u91cf\u7ea7\u7684\u7279\u70b9\uff0c\u5b89\u5168\u6027\u867d\u597d\uff0c\u4f46\u9700\u5f00\u53d1\u8005\u8fdb\u884c\u66f4\u591a\u624b\u52a8\u914d\u7f6e\u3002\u800cYii\u548cCakePHP\u7684\u5b89\u5168\u7279\u6027\u76f8\u8fd1\uff0c\u4f46\u5b83\u4eec\u5728\u793e\u533a\u548c\u6587\u6863\u652f\u6301\u65b9\u9762\u6709\u6240\u5dee\u5f02\u3002\u5728\u9009\u62e9\u6846\u67b6\u65f6\uff0c\u5e94\u6839\u636e\u9879\u76ee\u7279\u6027\u548c\u5f00\u53d1\u56e2\u961f\u7684\u7ecf\u9a8c\u6765\u9009\u62e9\u9002\u5408\u7684\u6846\u67b6\u3002<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>PHP\u6846\u67b6\u7684\u5b89\u5168\u6027\u4e3b\u8981\u53d6\u51b3\u4e8e\u54ea\u4e9b\u65b9\u9762\uff1f<\/strong><\/p>\n<p>PHP\u6846\u67b6\u7684\u5b89\u5168\u6027\u4e3b\u8981\u53d6\u51b3\u4e8e\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a1.\u6846\u67b6\u7684\u8bbe\u8ba1\uff1a\u4e00\u4e2a\u597d\u7684\u6846\u67b6\u5e94\u8be5\u6709\u5b8c\u5584\u7684\u5b89\u5168\u529f\u80fd\uff0c\u6bd4\u5982\u8f93\u5165\u9a8c\u8bc1\u3001\u8de8\u7ad9\u811a\u672c\u653b\u51fb\uff08XSS\uff09\u9632\u62a4\u3001SQL\u6ce8\u5165\u9632\u62a4\u7b49\u30022.\u66f4\u65b0\u7ef4\u62a4\uff1a\u53ca\u65f6\u66f4\u65b0\u6846\u67b6\u7248\u672c\u4ee5\u83b7\u53d6\u6700\u65b0\u7684\u5b89\u5168\u8865\u4e01\u662f\u4fdd\u6301\u6846\u67b6\u5b89\u5168\u6027\u7684\u91cd\u8981\u63aa\u65bd\u30023.\u793e\u533a\u652f\u6301\uff1a\u9009\u62e9\u6709\u6d3b\u8dc3\u793e\u533a\u652f\u6301\u7684\u6846\u67b6\u53ef\u4ee5\u53ca\u65f6\u83b7\u53d6\u5b89\u5168\u5efa\u8bae\u548c\u89e3\u51b3\u65b9\u6848\u30024.\u7f16\u7801\u89c4\u8303\uff1a\u5f00\u53d1\u4eba\u5458\u8981\u9075\u5faa\u5b89\u5168\u7684\u7f16\u7801\u89c4\u8303\uff0c\u5982\u907f\u514d\u786c\u7f16\u7801\u5bc6\u7801\u3001\u5408\u7406\u4f7f\u7528\u4f1a\u8bdd\u7ba1\u7406\u7b49\u3002<\/p>\n<p><strong>\u5982\u4f55\u4fdd\u969cPHP\u6846\u67b6\u7684\u5b89\u5168\u6027\uff1f<\/strong><\/p>\n<p>\u4e3a\u4e86\u4fdd\u969cPHP\u6846\u67b6\u7684\u5b89\u5168\u6027\uff0c\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u51e0\u79cd\u63aa\u65bd\uff1a1.\u5f00\u53d1\u4eba\u5458\u8fdb\u884c\u5b89\u5168\u57f9\u8bad\uff0c\u4e86\u89e3\u5e38\u89c1\u7684\u5b89\u5168\u6f0f\u6d1e\u548c\u653b\u51fb\u6280\u672f\uff0c\u9075\u5faa\u5b89\u5168\u7684\u7f16\u7801\u5b9e\u8df5\u30022.\u4f7f\u7528\u6846\u67b6\u81ea\u5e26\u7684\u5b89\u5168\u529f\u80fd\uff0c\u5982\u8fc7\u6ee4\u7528\u6237\u8f93\u5165\u3001\u9632\u6b62SQL\u6ce8\u5165\u7b49\u30023.\u5b9a\u671f\u5ba1\u8ba1\u4ee3\u7801\uff0c\u53d1\u73b0\u6f5c\u5728\u7684\u5b89\u5168\u6f0f\u6d1e\u5e76\u53ca\u65f6\u4fee\u590d\u30024.\u90e8\u7f72Web\u5e94\u7528\u9632\u706b\u5899\uff08WAF\uff09\u7b49\u5b89\u5168\u8bbe\u5907\uff0c\u589e\u5f3a\u5bf9\u6076\u610f\u653b\u51fb\u7684\u9632\u62a4\u80fd\u529b\u3002<\/p>\n<p><strong>\u6709\u54ea\u4e9b\u5e38\u89c1\u7684PHP\u6846\u67b6\u5b89\u5168\u6f0f\u6d1e\uff1f<\/strong><\/p>\n<p>\u4e00\u4e9b\u5e38\u89c1\u7684PHP\u6846\u67b6\u5b89\u5168\u6f0f\u6d1e\u5305\u62ec\uff1a1.\u8de8\u7ad9\u811a\u672c\u653b\u51fb\uff08XSS\uff09\uff1a\u653b\u51fb\u8005\u901a\u8fc7\u5728\u7f51\u9875\u4e2d\u6ce8\u5165\u6076\u610f\u811a\u672c\uff0c\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u6216\u8fdb\u884c\u5176\u4ed6\u653b\u51fb\u30022.SQL\u6ce8\u5165\uff1a\u653b\u51fb\u8005\u901a\u8fc7\u5728\u8f93\u5165\u6846\u4e2d\u6ce8\u5165SQL\u4ee3\u7801\uff0c\u5b9e\u73b0\u5bf9\u6570\u636e\u5e93\u7684\u975e\u6cd5\u8bbf\u95ee\u30023.\u6587\u4ef6\u5305\u542b\u6f0f\u6d1e\uff1a\u672a\u7ecf\u8fc7\u6ee4\u7684\u7528\u6237\u8f93\u5165\u53ef\u80fd\u88ab\u5f53\u4f5c\u6587\u4ef6\u5305\u542b\u8def\u5f84\uff0c\u5bfc\u81f4\u5305\u542b\u6076\u610f\u6587\u4ef6\u30024.\u4f1a\u8bdd\u52ab\u6301\uff1a\u653b\u51fb\u8005\u901a\u8fc7\u7a83\u53d6\u7528\u6237\u7684\u4f1a\u8bdd\u6807\u8bc6\u4fe1\u606f\uff0c\u83b7\u53d6\u672a\u7ecf\u6388\u6743\u7684\u8bbf\u95ee\u6743\u9650\u3002\u5f00\u53d1\u4eba\u5458\u5e94\u8be5\u5bf9\u8fd9\u4e9b\u6f0f\u6d1e\u6709\u6240\u4e86\u89e3\uff0c\u5e76\u91c7\u53d6\u76f8\u5e94\u7684\u9632\u8303\u63aa\u65bd\uff0c\u4ee5\u786e\u4fddPHP\u6846\u67b6\u7684\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u8ba8\u8bbaPHP\u6846\u67b6\u7684\u5b89\u5168\u6027\u6bd4\u8f83\u65f6\uff0cLaravel\u3001Symfony\u3001CodeIgniter\u3001Yii\u548cCakePHP [&hellip;]","protected":false},"author":1,"featured_media":74073,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/74070"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=74070"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/74070\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/74073"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=74070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=74070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=74070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}