Skip to content

优化 CORS_ALLOW_ORIGIN 逻辑:移除对 localhost127.0.0.1 的强制放行 #808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
L33Z22L11 opened this issue Apr 4, 2025 · 1 comment

Comments

@L33Z22L11
Copy link

我的个人博客(开源项目)中配置了 Twikoo 的实例地址,通过设置 CORS_ALLOW_ORIGIN 限制来源。近期发现自己的 Twikoo 实例被其他人本地测试时调用,CORS_ALLOW_ORIGIN 配置未生效。

通过阅读源码发现,即使明确配置了 CORS_ALLOW_ORIGIN,Twikoo 仍会强制放行 localhost127.0.0.1 等本地地址。若用户希望通过 CORS_ALLOW_ORIGIN 严格限制调用来源,本地测试地址的强制放行会绕过预期限制。当用户主动配置 CORS 时,框架应尊重配置而非默认覆盖。

建议解决方案
移除对本地地址的强制放行逻辑,或通过新增配置项(如 CORS_FORCE_ALLOW_LOCALHOST=false)允许用户关闭此行为。

附加信息

  • 使用场景:开源博客项目需限制评论接口调用来源。
  • 相关环境:Twikoo 版本 1.6.40,部署方式 Vercel。
@imaegoo
Copy link
Member

imaegoo commented Apr 5, 2025 via email

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

No branches or pull requests

2 participants