Injection in API HTTP request from frontend? - 資安

Table of Contents

新的系列 板上大家還是害羞提出問題

我有空的時候從 stackexchange 上面拿問題討論




來自 security.stackexchange.com [0] 的發問

標題是:Security implications of injection in api http request from frontend?

很像是設計 API 的工程師 初次接觸到資訊安全領域的人會提出來的問題

對於 API 實作方面上 擔心是否會出現 Injection 相關的安全性漏洞

他的提問算是蠻粗略的

像是 article = httpLibrary.get('api.mysite.com/articles/' + articleId); 這樣的函數

是否存在 CRLF 等其他的安全性問題




基本上我會選擇回答 這取決於你還做了哪些事情

單從一行 code 來看它本身當然沒啥問題 有機會出現問題的是 httpLibrary.get 的實作

既然是別人實作上的問題 那可能發生的漏洞就會很多

如果參照 OWASP Top 10 - A1 Injection [1] 的建議

要避免 Injection 的方式可以使用

- 安全的 API 代表要看 httpLibrary.get 是否太久沒更新、或者有安全性漏洞
- 白名單的輸入值檢查 做額外的 articleId 像是只允許數字
- 跳脫特殊字元 跳脫除了 A-Za-z0-9 以外的所有字元



[0]: https://security.stackexchange.com/questions/212908
[1]: https://www.owasp.org/images/7/72/OWASP_Top_10-2017_%28en%29.pdf.pdf

--

All Comments

Madame avatarMadame2019-07-07
thanks for sharing.
Callum avatarCallum2019-07-10