简体   繁体   English

从Play Framework中的请求获取主机名。 安全问题?

[英]Get hostname from request in Play Framework. Security issue?

I am using Play 2.2 and I need to send emails containing a link back to my application (for signup purposes). 我正在使用Play 2.2,需要发送包含指向我的应用程序链接的电子邮件(用于注册)。 For now the email is triggered by an API (which basically says "I want to request access to this app"). 目前,电子邮件是由API触发的(基本上说“我想请求访问此应用”)。 An email is received by the admin who can accept or deny the request, with a once token mechanism for security. 管理员会收到一封电子邮件,管理员可以接受或拒绝该请求,并具有一次令牌机制以确保安全。

I am using reverse routing and the absoluteURL() method to determine what the url I need to insert in the email is. 我使用反向路由和absoluteURL()方法来确定我需要在电子邮件中插入的URL。 This can't be hardcoded because the app runs on different environment / domain names so I want this to be dynamic. 这不能硬编码,因为该应用程序在不同的环境/域名上运行,因此我希望它是动态的。

However absoluteURL uses the request as an implicit parameter and get the URL from the Host header. 但是,absoluteURL将请求用作隐式参数,并从Host标头获取URL。 It's possible to forge a request with a different "Host" header and send it to my app, which can result in an email having a link like http://evil.com/acceptRequest?token=gfdklhggfd The token being legit since it was actually generated by my application. 可以伪造带有不同“主机”标头的请求,然后将其发送到我的应用程序,这可能导致电子邮件中包含类似http://evil.com/acceptRequest?token=gfdklhggfd的链接。实际是由我的应用程序生成的。

Is there a better way to do this without security issues ? 有没有更好的方法来做到这一点而没有安全问题?

An alternative would be to pass the host-name as part of the configuration - if each environment runs effectively as separate application. 另一种选择是将主机名作为配置的一部分传递-如果每个环境都作为独立的应用程序有效运行。

For example in application.conf 例如在application.conf中

hostName=${HOST_NAME}

And then set the environment variable HOST_NAME for the script that runs the play server. 然后为运行播放服务器的脚本设置环境变量HOST_NAME

That being said -- what could an attacker achieve with a forged URL? 话虽这么说-攻击者使用伪造的URL可以实现什么? Could an access key or the like be re-used for another host? 可以将访问密钥等用于其他主机吗? That is where I would try to make things secure. 那是我要确保事物安全的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM