yihong0618 / running_page

Make your own running home page
https://running-page.vercel.app
MIT License
3.4k stars 977 forks source link

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

Closed changchiyou closed 2 months ago

changchiyou commented 2 months ago

https://github.com/yihong0618/running_page/blob/e05b665865af61071eab78d042cf9257b38fef9f/src/utils/const.ts#L3

yihong0618 commented 2 months ago

嗯,对

changchiyou commented 2 months ago

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

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

yihong0618 commented 2 months ago

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

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

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

PR welcome

orionna319 commented 2 months ago

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

orionna319 commented 2 months ago

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

changchiyou commented 2 months ago

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

changchiyou commented 2 months ago

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

changchiyou commented 2 months ago
  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 https://github.com/changchiyou/running_page/commit/c33d7f56641f4fe77cfa585183ce79bf3a67acb8

  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 commented 2 months ago

@yihong0618 @orionna319 看起來確實如 https://github.com/yihong0618/running_page/issues/643#issuecomment-2041976662 所說不用重構專案,但需要根據 https://github.com/yihong0618/running_page/issues/643#issuecomment-2042668580 更新README.md / 於src/utils/const.ts對應位置上新添加提示 command

orionna319 commented 2 months ago

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

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

orionna319 commented 2 months ago

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

changchiyou commented 2 months ago

当然比较好的处理方式是,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 中(滿足包含我在內一部分對資安比較敏感開發者的強迫症 🤣)。