iT邦幫忙

2024 iThome 鐵人賽

DAY 26
0
自我挑戰組

利用 node.js/express 架設網站系列 第 26

Day-26 應用程式安全性(上)

  • 分享至 

  • xImage
  •  

接下來兩天將會把這個應用的安全性實裝上去,要增加安全性有幾種方法:

  • 密碼加密
  • JWT身份驗證
  • 防止跨站點請求偽造(CSPF)
  • Helmet頭部保護
  • 防止跨站腳本攻擊
  • 限制API請求速率
  • HTTP加密
  • 隱藏敏感資訊

本次我會使用JWT、Helmet、HTTP加密和限制API速率來增加安全性:

JWT身份驗證

首先需要安裝
接著先做出一個中間件:
https://ithelp.ithome.com.tw/upload/images/20241010/20169465aq26F12A86.png
接著再把需要受到JWT保護的路由都加上中間件:
https://ithelp.ithome.com.tw/upload/images/20241010/20169465lkFDpiO5k8.png
https://ithelp.ithome.com.tw/upload/images/20241010/201694659EhKue43rO.png
https://ithelp.ithome.com.tw/upload/images/20241010/20169465nTLFfkPHGZ.png
https://ithelp.ithome.com.tw/upload/images/20241010/20169465dKRAKlX5k3.png

Helmet頭部保護

要製作頭部保護,我們就需要先 npm install helmet
接著就只需要引入這個模組就好
https://ithelp.ithome.com.tw/upload/images/20241010/20169465hv6zHTYgPQ.pnghttps://ithelp.ithome.com.tw/upload/images/20241010/20169465ytmOpNIsdf.png

今天先製作這兩個,明天將會把剩下兩個完成。


上一篇
Day-25 分辨賣家身份和成為賣家
系列文
利用 node.js/express 架設網站26
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言