Skip to content

fix: 评论私密接口未授权风险和无法切换私密状态 - #75

Merged
Shiroiame-Kusu merged 1 commit into
Fuukei:mainfrom
ranfey:main
Aug 16, 2026
Merged

fix: 评论私密接口未授权风险和无法切换私密状态#75
Shiroiame-Kusu merged 1 commit into
Fuukei:mainfrom
ranfey:main

Conversation

@ranfey

@ranfey ranfey commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

演示

1. 评论私密接口未授权风险

所有评论的私密状态可以随意被更改

评论私密切换接口同时注册了未登录 AJAX 入口,并且请求不需要 nonce:

add_action('wp_ajax_nopriv_siren_private', 'siren_private');
add_action('wp_ajax_siren_private', 'siren_private');

REST API 获取最近评论 ID:

GET /wp-json/wp/v2/comments?per_page=XXXX&orderby=date&order=desc

返回第一项里的 id 即为后续 AJAX 请求的 p_id

image-20260809192359670

可构造请求:

POST /wp-admin/admin-ajax.php
action=siren_private&p_id=XXXX&p_action=set_private

image-20260809191614579

2. 评论私密状态无法正确切换

只会写入私密状态:

update_comment_meta($comment_id, '_private', 'true');

评论只能被设为私密,不能再次点击恢复公开

recording

修复内容

对应

mirai-mamori/Sakurairo#1422

src/page/index.js

  • 从按钮读取 data-noncep

  • AJAX 请求追加 _wpnonce

let ajax_data = "action=siren_private&p_id=" + idp + "&p_action=" + actionp + "&_wpnonce=" + noncep;
  • 移除 private_now 判断
  • 确认文案改为“您确定要切换私密状态吗?”

验证

修复后

recording

image-20260809194938004

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 旨在修复评论“切换私密状态”功能的安全风险与交互问题:前端请求增加 nonce 参数,并调整确认提示与切换逻辑,以支持重复切换而非只能设为私密一次。

Changes:

  • 更新确认文案为“您确定要切换私密状态吗?”
  • 从按钮读取 data-noncep 并在 AJAX 请求中追加 _wpnonce
  • 移除 private_now 的前端拦截逻辑,允许再次点击触发切换

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/page/index.js
Comment on lines 241 to +245
let idp = list.getAttribute("data-idp"),
actionp = list.getAttribute("data-actionp"),
rateHolderp = list.getElementsByClassName('has_set_private')[0];
let ajax_data = "action=siren_private&p_id=" + idp + "&p_action=" + actionp;
rateHolderp = list.getElementsByClassName('has_set_private')[0],
noncep = list.getAttribute("data-noncep");
let ajax_data = "action=siren_private&p_id=" + idp + "&p_action=" + actionp + "&_wpnonce=" + noncep;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后端校验的是绑定评论 ID 的 siren_private_{comment_id} nonce,不是全局 nonce

Comment thread src/page/index.js
let ajax_data = "action=siren_private&p_id=" + idp + "&p_action=" + actionp;
rateHolderp = list.getElementsByClassName('has_set_private')[0],
noncep = list.getAttribute("data-noncep");
let ajax_data = "action=siren_private&p_id=" + idp + "&p_action=" + actionp + "&_wpnonce=" + noncep;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在另一个仓库 mirai-mamori/Sakurairo#1422

Shiroiame-Kusu added a commit to ranfey/Sakurairo that referenced this pull request Aug 16, 2026
- zh_CN/zh_TW/ja/fr 补充 "Are you sure you want to toggle private status?" 翻译并重新编译 .mo
- 移除已废弃的 "Are you sure you want set it private?" 与 "You had set private comment before"
- 还原 js/page.js 与 js/page.js.map:构建产物由 Fuukei/Sakurairo_Scripts#75 经同步流程生成,不在本仓库手动提交
@Shiroiame-Kusu
Shiroiame-Kusu merged commit 6190189 into Fuukei:main Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants