Skip to content
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

資安疑慮:Mapbox token 只能明碼寫在const.ts中? #643

Closed
changchiyou opened this issue Apr 8, 2024 · 12 comments
Closed

資安疑慮:Mapbox token 只能明碼寫在const.ts中? #643

changchiyou opened this issue Apr 8, 2024 · 12 comments

Comments

@changchiyou
Copy link
Contributor

'pk.eyJ1IjoieWlob25nMDYxOCIsImEiOiJja2J3M28xbG4wYzl0MzJxZm0ya2Fua2p2In0.PNKfkeQwYuyGOTT_x9BJ4Q';

@changchiyou changchiyou changed the title 資安疑慮:Mapbox token 只能明碼寫在const.tx中? 資安疑慮:Mapbox token 只能明碼寫在const.ts中? Apr 8, 2024
@yihong0618
Copy link
Owner

嗯,对

@changchiyou
Copy link
Contributor Author

@yihong0618 我隨意問了下 ChatGPT https://chat.openai.com/share/1db41f61-a363-44fb-a63a-a5701e922bf4 ,請問這是可行的嗎?

如果並非架構問題 / 以前有踩過無法處理的坑,那我會想試試看發 PR 來處理這個問題。

@yihong0618
Copy link
Owner

@yihong0618 我隨意問了下 ChatGPT https://chat.openai.com/share/1db41f61-a363-44fb-a63a-a5701e922bf4 ,請問這是可行的嗎?

如果並非架構問題 / 以前有踩過無法處理的坑,那我會想試試看發 PR 來處理這個問題。

抱歉哈我忘了,这个 mapbox 怎么处理的了(这块两年没改了),理论上不需要改,我晚上研究研究。

PR welcome

@orionna319
Copy link
Collaborator

如果觉得有安全问题的话,可以放在settings/secrets/actions。然后在const.ts文件中读取secrets,欢迎PR。

@orionna319
Copy link
Collaborator

如果读取不到尽量给一个默认值,向前兼容。

@changchiyou
Copy link
Contributor Author

@yihong0618 @orionna319 感謝回復,我晚點處理看看

@changchiyou
Copy link
Contributor Author

changchiyou commented Apr 8, 2024

  • https://stackoverflow.com/a/21941683

    In short, no. If your GitHub repo is public, all its assets are public. You can make the repo private and it will still publish on GitHub Pages if named with the username.github.io convention or if it has a gh-pages branch. While that's an option, that's not necessarily the right thing to do.

  • https://stackoverflow.com/a/61857467

    image image

如果想藉由改動專案結構來處理這問題,好像不管如何都避不開

@changchiyou
Copy link
Contributor Author

  1. 參考

    1. https://docs.mapbox.com/help/getting-started/access-tokens/#url-restrictions

      image
    2. https://docs.mapbox.com/accounts/guides/tokens/#url-restrictions

      image

    Account | Mapbox - Tokens 新增一個 token:

    image
  2. 並參考

    image

    中的Origin: https://changchiyou.github.io設置URLs

    image image
  3. push commit 更新 Mapbox token changchiyou@c33d7f5

  4. 手動執行 Run Data Sync Github Action:
    image

  5. (✅ 成功)shift+command+R 重整頁面 https://changchiyou.github.io/running_page/

  6. (✅ 成功: 理應失敗,因為沒有從指定的 origin URL 發 request)curl 2.中的 request:

    curl https://api.mapbox.com/v4/mapbox.mapbox-streets-v8,mapbox.mapbox-terrain-v2.json\?secure\&access_token\=pk.eyJ1IjoiY2hhbmdjaGl5b3UiLCJhIjoiY2x1cXd2MWRxMDExZzJqcXJyNTVjbnVwOSJ9.hOsDM-tbwwCAAsDHWHYkFQ
    
    image

@changchiyou
Copy link
Contributor Author

@yihong0618 @orionna319 看起來確實如 #643 (comment) 所說不用重構專案,但需要根據 #643 (comment) 更新README.md / 於src/utils/const.ts對應位置上新添加提示 command

@orionna319
Copy link
Collaborator

好像是的,就算存储在settings/secrets中,在web端也会显示调用MAPBOX_TOKEN

如果想藉由改動專案結構來處理這問題,好像不管如何都避不開

@orionna319
Copy link
Collaborator

orionna319 commented Apr 8, 2024

当然比较好的处理方式是,MAPBOX_TOKEN放在settings/secrets下,然后再设置Mapbox-URLs

@changchiyou
Copy link
Contributor Author

changchiyou commented Apr 8, 2024

当然比较好的处理方式是,MAPBOX_TOKEN放在settings/secrets下,然后再设置Mapbox-URLs

@orionna319 如果你上面那段(關於Mapbox-URLs這看不大懂)指的是 https://stackoverflow.com/questions/21939713/hide-api-key-for-a-github-page/61857467#61857467

確實,資安不求完美但也不嫌多,這樣的做法雖說不能避免 Client 端從瀏覽器開發者工具看到 Mapbox token,但確實能避免明碼將 token 寫在 repo 中(滿足包含我在內一部分對資安比較敏感開發者的強迫症 🤣)。

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

3 participants