WordPress官方的代码审查意见

There are issues with your plugin code.

Please read this ENTIRE email, address all listed issues, and reply to this email with your corrected code attached. It is required for you to read and reply to these emails, and failure to do so will result in significant delays with your plugin being accepted.

Also please remember in addition to code quality, security and functionality, we require all plugins adhere to our guidelines. If you have not yet, please read them:

## Please sanitize, escape, and validate your POST calls

When you include POST/GET/REQUEST calls in your plugin, it’s important to sanitize, validate, and escape them. The goal here is to prevent a user from accidentally sending trash data through the system, as well as protecting them from potential security issues.

SANITIZE: All instances where generated content is inserted into the database, or into a file, or being otherwise processed by WordPress, the data MUST be properly sanitized for security. By sanitizing your POST data when used to make action calls or URL redirects, you will lessen the possibility of XSS vulnerabilities. You should never have a raw data inserted into the database, even by a update function, and even with a prepare()  call.

VALIDATE: In addition to sanitization, you should validate all your calls. If a $_POST call should only be a number, ensure it’s an int() before you pass it through anything. Even if you’re sanitizing or using WordPress functions to ensure things are safe, we ask you please validate for sanity’s sake. Any time you are adding data to the database, it should be the right data. ESCAPE: Similarly, when you’re outputting data, make sure to escape it properly, so it can’t hijack admin screens. There are many esc_*() functions you can use to make sure you don’t show people the wrong data. In all cases, using stripslashes or strip_tags is not enough. You need to use the most appropriate method associated with the type of content you’re processing. Check that a URL is a URL and don’t just be lazy and use sanitize_text please. The ultimate goal is that you should ensure that invalid and unsafe data is NEVER processed or displayed. Clean everything, check everything, escape everything, and never trust the users to always have input sane data. Please review this document and update your code accordingly: http://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data Example: WordPress comes with an extensive HTTP API that should be used instead of creating your own curl calls. It’s both faster and more extensive. It’ll fall back to curl if it has to, but it’ll use a lot of WordPress’ native functionality first. —- Please make sure you’ve addressed ALL issues brought up in this email. 译文： 你的代码有问题。 请阅读整封邮件，处理当中列出的所有问题，并回复这封邮件，附上你修正后的代码。你必须阅读并回复这些邮件，否则你的插件被接受的时间将会被严重推迟。 另外请记得，除了代码质量、安全和功能外，我们要求所有插件都遵循我们的指南。如果你还没有这么做，请先读一读： ## 请净化、转义并验证你的POST调用。 当你在你的插件中包含POST/GET/REQUEST调用时，对它们进行净化、验证和转义是很重要的。这样做的目的是阻止用户通过系统发送垃圾数据，并保护他们免受潜在安全问题的侵害。 净化：每当生成的数据需要插入到数据库中，或文件中，或者要被WordPress处理的时候，为了安全，该数据都必须被适当净化。净化action调用或URL重定向所用的POST数据可以减少XSS漏洞。永远不要将一条原始数据插入到数据库中，即便是通过一个update函数，甚至是一个 prepare() 调用。 验证：在净化之外，还要验证你的所有调用。如果一个$_POST调用应该只是一个数字，在将它传递给任何东西之前，确保它是一个 int() 。即便你正在净化或使用WordPress函数以确保安全，我们还是请求你做个验证以确保合理。每当添加一条数据到数据库中时，它都应该是一条正确的数据。

WordPress提供了大量的HTTP API，你应该使用它们而不是创建你自己的curl调用。这样更快也更具扩展性。这种做法在不得已的情况下会退而使用curl，但会首先使用大量WordPress自身的功能。

—-

关于代码审查（Code Review）的一些建议

2016-10-27 22:00:51

代码与批注

2015-01-01 14:44:10

论代码审查的重要性

2016-06-22 11:19:52

代码审查表和代码审查实例

2008年12月31日 33KB 下载

WordPress主题文件的执行顺序及其层次结构详解

2014-12-13 20:45:12

代码审查“查”什么？

2017-11-18 20:34:06

代码审查学习总结

2017-07-18 14:43:38

android如何进行版本迭代及代码审核

2017-03-25 12:34:28

wordpress一款企业主题

2012年08月07日 885KB 下载

代码审查如何做

2017-01-22 23:05:46