php / php/php-src

add preg_quote_replacement() function

未关闭
#9,663 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Extension: pcre Feature Status: Needs Triage
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

Description
$pattern = '/[[name]]/';
$template = 'My name is [[name]]';
preg_replace($pattern, $_POST['name'], $template);

This is prone to injection of any match from the pattern if user supplies for example Tomas$1Fejfar. There is a preg_quote function that can be used to escape special chars in template. There should be same function that would escape the replacement.

preg_quote_replacement($_POST['name']); // Tomas\$1Fejfar

IMHO it is enough to escape backslash and dollars with backslash, but I am not sure.

Currently the replacement must be escaped using userland function that makes it prone to mistakes.

贡献指南

打开贡献指南

从这里开始

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

调研方向

该 issue 提到了 preg_quote() 和 preg_replace(),但没有提供文件或测试。首先跟踪它们的实现和替换解析,然后针对所示的注入案例,验证对反斜杠和美元符号的拟议处理方式。完成的标准是定义转义契约、实现新函数,并为 Tomas$1Fejfar 之类的替换字符串添加覆盖。

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

评估

技术栈
php
领域
backend
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

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