duanlie4621 2015-10-20 14:13
浏览 35

选择一个秘密

I am currently doing a little study on what I can possibly do to secure the cookie data I send to my client. It turns out that it all boils down to signing my cookies - not a big deal, right?

Well, actually, that is only partially true. I am stuck at deciding what secret to use. You see, my app is open-sourced and I won't suddenly close the open source code down. So I need a mechanism that'd allow me to keep the secret a serious secret, and make sure the end user, that reads through my code, won't immediately be able to break through. Because, anything is hackable if you tinker with it long enough - that's how I see it.

Anyway I am getting off topic.

I am working with PHP and NodeJS. What are the best ways to pick a secret, that will forever stay a secret?

My initial thoughts: - My server's private key - A random string, put into a text file outside of world-access

My app currently runs Yii1, but I am switching to laravel 5.

  • 写回答

1条回答 默认 最新

  • dta43039 2015-10-20 16:12
    关注

    It turns out that it all boils down to signing my cookies - not a big deal, right?

    Be very careful here. Many people attempted to implement such a feature before, only to render their apps remotely exploitable.

    I would almost argue that you shouldn't write this yourself. One of the features I'm building for my libsodium wrapper library is an authenticated encryption wrapper for HTTP cookies.

    What are the best ways to pick a secret, that will forever stay a secret?

    Easiest: Using 32 bytes from /dev/urandom, stored in a configuration file outside of your document root.

    Most secure: Use a HSM so your keys are never accessible, even if an attacker gets root on your server.

    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接