Skip to content

[Bug] After introducing cross-origin with reverse proxy, cleaning up other directives can cause functional conflicts in other if blocks. #10747

@HynoR

Description

@HynoR

Contact Information

No response

1Panel Version

2.0.12

Problem Description

今天在研究反向代理的时候发现,新版本如果不开跨域去设置浏览器缓存,浏览器缓存不会被正确设置。因为下面跨域有一个 removeDirective,把所有符合 if ( 的块全删掉了

Steps to Reproduce

反向代理设置浏览器缓存+反向代理不启用跨域 = 浏览器缓存不会正确设置
反向代理设置浏览器缓存+反向代理启用跨域 = 浏览器缓存正确设置
反向代理设置浏览器缓存+反向代理启用跨域,但不启用预检 = 浏览器缓存不会正确设置

原因在于 location.RemoveDirective("if", []string{"(", "$request_method", "=", "'OPTIONS'", ")"})
RemoveDirective 只会快速比对 key 和第一个 param,原本是来移除符合 key 和 value 的 directive,但是对于 if 这种 后面值跟的是一个规则或者表达式,会直接删除符合key 和表达式第一个字符的所有块内指令。
所以导致这个函数等效于 location.RemoveDirective("if", []string{"(")

第一种方法复现截图
Image

The expected correct result

No response

Related log output

Additional Information

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions