php - 在没有 SSL/OAuth 的情况下向 Wordpress 提交评论

标签 php wordpress ssl

我想让 android/iPhone 用户匿名(无需注册博客)向自托管的 Wordpress 博客提交评论。

是否有一种简单、安全的方法来做到这一点?

到目前为止我研究了什么:

JSON API 插件 -> 运行良好,但不安全。

WP-API -> 没有实现提交评论方法 + 没有安全性。

最佳答案

好吧,你可以只使用随机数来避免 XSS 攻击,除此之外你显然需要你的用户登录。这是一个简单的方法来做到这一点。

https://wordpress.org/support/topic/plugin-json-api-how-to-add-a-comment-or-post

编辑:如果您只需要能够使用他们的姓名和电子邮件地址发表评论。如下使用它,但请确保您从 api 设置中启用“响应 Controller ”

http://yourwebsite.com/api/?json=submit_comment&post_id=170&name=Omer&email=commenter@gmail.com&content=comment

第二次编辑:为了保护评论,您可以使用随机数,如果它不是插件的内置功能,您必须在 submit_comment Controller 中添加此功能。但是从你的 android 应用程序生成随机数会有点困难。一个简单的解决方案是将现有代码包装在一个条件中。类似于 base64 编码的时间 token 。

if(isset($_GET['token'])){
  $token = base64_decode($_GET['token']);
  $current_time = time();
  $difference = round(abs($current_time - $token) / 60,2);//difference in minutes
  if($difference < 5){
      // Run the code thats already in submit_comment controller.
  }
}

然后在 REST api 中,您可以发送类似

的内容
http://yourwebsite.com/api/?json=submit_comment&post_id=170&name=Omer&email=commenter@gmail.com&content=comment&token=BASE64_ENCODED_TIMESTAMP

关于php - 在没有 SSL/OAuth 的情况下向 Wordpress 提交评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28979381/

相关文章:

php - Laravel mongodb 聚合

Php - 通知 : Undefined offset 10?

php - 从 wordpress 编辑页面屏幕中删除主编辑器

python - 在带有 Google Cloud 服务的 Python 中使用多处理时出现 SSL 错误

python - 如何更新 certifi 的根证书?

java - 试图将 Activity 转换为 fragment

php - 什么时候使用 PDO 常量 PDO::PARAM_STR?

php - 刷新页面时用户已注销

mysql - WordPress 在其 MySQL 数据库中对其内容编码做了什么?

windows - 如何强制 JBoss AS 7.0.1 SSL 连接器协议(protocol)仅使用 TLS 1.2