Names with an apostrophe break the XPath queries in RtLocks, RtCounters, and RtCounter

未关闭 适合新手
#145 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
backend, security

调研方向

从 src/main/java/co/stateful/RtLocks.java、RtCounter.java 和 RtCounters.java 开始,issue 在这些文件中展示了三个会插入名称的 XPath 表达式。阅读这些方法如何构建和执行查询,然后在这三个位置统一采用一种安全的 XPath 字面量处理方法。完成标准是:对于列出的操作,包含任一种或两种引号的名称都能正常工作,同时不改变所选项目。

由索引模型根据 Issue 内容生成。

描述

A lock or counter name that contains a single quote makes the XPath expression invalid, so the call fails instead of finding the item.

The name is pasted straight into a single-quoted XPath literal:

// src/main/java/co/stateful/RtLocks.java:53
.nodes(String.format("/page/locks/lock[name='%s']", name))

// src/main/java/co/stateful/RtCounter.java:93
"/page/counters/counter[name='%s']/links/link[@rel='%s']/@href"

// src/main/java/co/stateful/RtCounters.java (delete)
"/page/counters/counter[name='%s']/links/link[@rel='delete']/@href"

Take locks.exists("it's"): the expression becomes /page/locks/lock[name='it's'], which is malformed XPath, so exists throws instead of returning a boolean. The same happens in counter.set(...), counter.incrementAndGet(...), and counters.delete("it's"). A name like x' or '1'='1 changes the query and may select another item.

Fix: build the XPath literal safely. Either pass the name as an XPath variable, or write a small helper that wraps the value in double quotes when it has a single quote, and uses concat(...) when it has both kinds of quotes. Use it in all three places.

主要语言
Java
星标
10
派生
3
平均合并
4 小时 33 分钟
30 天内合并 PR
7

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

sttc/java-sdk 的其他 Issue

查看 sttc/java-sdk 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。