php - PHP警告消息公开了OAuth应用的 secret

标签 php security error-handling

我正在使用OAuth2授权应用程序的Facebook帐户。我刚刚发现,如果访问 token 请求失败,file_get_contents将显示完整的请求URL,其中包含敏感数据,例如 secret 应用程序ID(client_id/client_secret)。
如何处理这类事情?有没有办法显示警告消息但不暴露那些路径?

Warning: file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=123&redirect_uri=https%3A%2F%2Fwww.example.com%2Foauth%2Ffacebook.php&client_secret=123&code=123) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in oauth/facebook.php on line 113

最佳答案

使用try catch块在php中轻柔地处理错误。由于您使用的是Facebook OAuth,因此只需在try catch中包含方法/函数,如下所示
try { "...facebook oauth function here..." } catch (Exception $e) { echo $e->getMessage(); }
如果这可以解决您的问题,请告诉我。

问候,
HBK

关于php - PHP警告消息公开了OAuth应用的 secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22870537/

相关文章:

security - Solr 中的细粒度安全性

windows - 有没有比 Windows DPAPI 更安全的方法来保护和存储密码?

c++ - 为模板类中的无效数据类型生成编译时错误?

php - set_exception_handler()期望参数(exception_handler)是有效的回调

javascript - 如何 - 我有一个用于时间日期格式的 js,我希望将其添加到我的 ajax 帖子中并发送到 php

php - 组合数组元素

javascript - WebcryptoAPI - 安全与否?

php - 函数获取ogt_preww

wordpress - 如何从functions.php在自定义login.php中显示wp错误

PHP mySql - 更改语句以不删除某些值?