php / php/php-src

Inconsistent handling of invalid headers causes unexpected behavior

未关闭
#19,858 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Description

The following code:

<?php
header( "X-Foo;: hello" );
header( "X-Foo\t: hello" );
header( "X-Foo\n: hello" );

The 3rd one results in a warning (Header may not contain more than a single header, new line detected) and the header is not set.
The other 2 however are sent without a warning. The 2nd one will get fixed by nginx, however the 1st one passes through (see https://github.com/nginx/nginx/issues/899)

This not only is inconsistent, this also allows for certain attack vectors if the request is proxied and the proxy does not handle the invalid headers correctly (sorry, can't go into detail on this at this moment in time, due to pending security reports)

Since headers are apparently getting validated in PHP already (otherwise we wouldn't have an error for the 3rd one), this validation should be fixed to strictly check if the provided header adheres to the HTTP header standards

PHP Version
PHP 8.4, however affects previous PHP versions similarly
Operating System

No response

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先重现 issue 中描述的三个 header() 调用,并检查 PHP 的 header 验证路径,了解分号、制表符和换行符的处理方式。当无效的 header 语法都能通过适当的警告被一致拒绝,且有效的 header 不受影响时,工作就完成了;为这三个示例添加覆盖测试。

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

评估

技术栈
c, php
领域
backend-api-design, security
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

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