Goããã°ã©ãã³ã°èšèªã¯ããªãæ°ããããã°ã©ãã³ã°èšèªã§ã-2007幎ã«Googleã«ãã£ãŠéçºããã2009幎ã«æ£åŒã«å°å ¥ãããŸããã ããã°ã©ããŒã¯ãã®èšèªãæ¬åœã«å¥œãã§ããïŒã³ã³ãã€ã«æžã¿ããã«ãã¹ã¬ãããæ§é åãåœä»€åã MicrosoftãGitHubãCloudflareãHerokuãVkontakteãMail.Ruãªã©ã®äŒæ¥ã§äœ¿çšãããŠããŸãã èšèªã®ãªãªãŒã¹çŽåŸã«ãGoã§ã®éçºãæ¯æŽããã©ã€ãã©ãªãšããŒã«ãç»å ŽããåŒãç¶ãäœæãããŸããã Webã¢ããªã±ãŒã·ã§ã³ãä¿è·ããããã®ã©ã€ãã©ãªããããã®ããŒã«ã«å«ãŸããŠããŸãã åã ã®éçºè ã«ãã£ãŠæžãããå€ãã®ã©ã€ãã©ãªããã©ã€ãã©ãªã®æšæºã»ããã«çµã¿èŸŒãŸããŠããŸãã
以äžã¯ããµã€ãã«å¯Ÿããæãäžè¬çãªæ»ææ¹æ³ãšãããããåé¿ããããå°ãªããšããããã®è åšãæå°éã«æããäž»ãªæ¹æ³ã§ãã
- ã»ãã·ã§ã³IDã®äºæž¬å€ïŒè³æ Œæ å ±/ã»ãã·ã§ã³äºæž¬ïŒã
- ã¯ãã¹ãµã€ããªã¯ãšã¹ããã©ãŒãžã§ãªïŒCSRFïŒã
- ã¯ãã¹ãµã€ãã¹ã¯ãªããã£ã³ã°ïŒXSSïŒã
- ã¯ãªãã¯ãžã£ããã³ã°ã
- SQLã¹ããŒãã¡ã³ãã®æ³šå ¥ïŒSQLã€ã³ãžã§ã¯ã·ã§ã³ïŒã
ãããã®çš®é¡ã®æ»æããä¿è·ããããã®ããŒã«ã®æŠèŠã
ã»ãã·ã§ã³ãšCookieãæ£ããä¿è·ãã
ã»ãã·ã§ã³ã¯ãèªèšŒãå¿ èŠãšããã«WebãµãŒããŒã«ã¢ã¯ã»ã¹ããããã«äœ¿çšã§ãããããããã«ãŒã«ãšã£ãŠæ確ãªã¿ãŒã²ããã§ãã ãããŠãã»ãã·ã§ã³ã®é©åãªå®è£ ããµãŒãã¹å šäœãå±éºã«ãããå¯èœæ§ãããããšãå€æããŸããã WebãµãŒãã¹ã§ã»ãã·ã§ã³ã䜿çšããå Žåã¯ã ãŽãªã©ã©ã€ãã©ãªã圹ç«ã¡ãŸãã Gorillaã®ã»ãã·ã§ã³ã¯ããµãŒããŒãžã®Cookieã®ä¿åã«å¯ŸåŠããã®ã«åœ¹ç«ã€ã ãã§ãªããåã«äžæã®ããŒã¯ã³ã転éããŸãã ããã«ã SecureCookieã©ã€ãã©ãªã圹ç«ã€å ŽåããããŸãã ãã®ãããªã»ãã¥ã¢Cookieã¯ãHMACã䜿çšããŠå€ãæ€èšŒããããããåœé ã§ããŸããã
æè¿ã JSON WebTokensãã¯ãããžãŒãéåžžã«é »ç¹ã«äœ¿çšãããŠããŸãã jwt-goã©ã€ãã©ãªã¯ãããæ¯æŽããŸãã Goã®JWTã®è©³çŽ°ã«ã€ããŠã¯ã ãã¡ããã芧ãã ãã ã
CSRF
次ã«ããµã€ãã«å¯Ÿããã¯ãã¹ãµã€ããªã¯ãšã¹ããã©ãŒãžã§ãªãŸãã¯CSRFæ»æãšã®æŠããæ€èšããŸãã CSRFæ»æã¯ããã®ã¢ããªã±ãŒã·ã§ã³ã®è匱æ§ã䜿çšããŠãWebã¢ããªã±ãŒã·ã§ã³ã®èš±å¯ããããŠãŒã¶ãŒã«å¯ŸããŠå®è¡ãããŸãã ããšãã°ãæ»æè ã¯ïŒãªã³ã¯ä»ãã®æçŽãéä¿¡ããããšã§ïŒæªæã®ããæäœïŒæ»æè ã®ã¢ã«ãŠã³ããžã®ééããã¹ã¯ãŒãã®å€æŽãªã©ïŒãå®è¡ããç¹å¥ã«æºåããããµã€ãã«ãŠãŒã¶ãŒã匷å¶çã«ç§»åã§ããŸãã ãã®æ»æãå®è¡ããã«ã¯ããªã¯ãšã¹ããéä¿¡ããããµãŒããŒã§è¢«å®³è ãèªèšŒããå¿ èŠããããŸãã CSRFæ»æãé²ãã«ã¯ãç¹å¥ãªç§å¯éµãçæããŠãŠãŒã¶ãŒã®ã»ãã·ã§ã³ã«ä¿åãããã®ç§å¯éµã«åºã¥ããŠãç¹å®ã®ã«ãŒã«ã«åŸã£ãŠããŒã¯ã³ãçæããŸãã ããŒã¯ã³ã¯ãäžæ¹ã§ã¯ããŒãšã¯ç°ãªãããã«ïŒç¹ã«ãäžæ¹ã®ããŒã«ã¯å€ãã®ããŒã¯ã³ãååšããå¯èœæ§ãããïŒãä»æ¹ã§ã¯ãã®ããŒã«åºã¥ããŠçæããããã©ãããããŒã¯ã³ã§ç°¡åã«ç¢ºèªã§ããããã«äœæãããŸãã 2015幎ãç 究è ã®Mikhail Firstovã¯Yotaã®Webãµã€ãã§åæ§ã®è匱æ§ã«ééããŸããã æè¿ãå€ãã®ãã€ã¯ããœãããµãŒãã¹ã§csrfã®è匱æ§ãçºèŠããããšã§ã1人ã®è±åœã®ç 究è ã« 13,000ãã«ãããããããŸããã ããã¯ãéçºè ããã®åé¡ããŸã ååã«è§£æ±ºããŠããããåžžã«èœåããããšã¯éããªãããšã瀺åããŠããŸãã
NoSurfã©ã€ãã©ãªã¯Goã§éåžžã«è¯ãä»äºãããŠããŸãã ã©ã€ãã©ãªã®äŸãšããŠãããã°ã©ã ã³ãŒãã瀺ããŸãã
ã芧ã®ãšããããªã¯ãšã¹ãã®ã³ã³ããã¹ãã«åºã¥ããŠãããŒã¯ã³ã圢æããããã®åŸãå¿ èŠãªãã£ãŒã«ããšããããŒã«æ¿å ¥ãããŸãã
ãœãŒã¹ããã±ãŒãžhtmlãããŠã³ããŒãããŸãã
èŠæ±ãã©ãŒã ã§ããŒã¯ã³ãå€æŽããããšãããšããµãŒããŒã¯ãšã©ãŒçªå·400 BadRequestãè¿ããŸãã
åæ§ã®GojiCSRFã©ã€ãã©ãªãèŠã€ããŸããã SecureCookieã䜿çšããŠããã«åäœãã32ãã€ãé·ã®ããŒã¯ã³ãçæããŸãã ããŒã¿ãå€æŽã§ãããªã¯ãšã¹ãã§ã®ã¿æ©èœããå®å šãªhttpã¡ãœããïŒGETãHEADãOPTIONSãTRACEïŒã§ã¯æ©èœããŸããã
ã»ãŒåãã§ãããç°¡æã¢ãŒãã§ã®ã¿ãæšæºã®Go XSRFtokenã©ã€ãã©ãªãçæã§ããŸãã funcGenerateãšfuncValidã®2ã€ã®æ©èœã ãã§ãªããããŒã¯ã³ã®æå¹æéãèšå®ããæ©èœããããŸãã
Xss
XSSæ»æãŸãã¯ã¯ãã¹ãµã€ãã¹ã¯ãªããã£ã³ã°ã¯ãWebã·ã¹ãã ãçºè¡ããããŒãžã«æªæã®ããã³ãŒããå°å ¥ããããšã§æ§æããããWebã·ã¹ãã ã«å¯Ÿããæ»æã®äžçš®ã§ãã æãæåãªäŸã¯ãæ»æè ã«ãããŠãŒã¶ãŒCookieã®ãã€ãžã£ãã¯ã§ãã
ç§ã®æèŠã§ã¯ãåé³ã®ååãæã€éåžžã«åªããã©ã€ãã©ãªããã®ã±ãŒã¹ã®ããã«æžãããŸããã ããã¯ãã©ã㯠ãã©ã€ããŒãšãã«ãŒã¢ã³ããŒã§ãã ã©ã€ãã©ãªã¯ããã«ã»ããã¢ããã§ãã䟿å©ã«å®è¡ã§ããŸãã 圌ãã¯äžç·ã«ãããŠå¥ã ã«åãããšãã§ããŸãã 圌ã¯ãã³ã³ãœãŒã«ããè¡ãåãåããç¹å®ã®æåããšã¹ã±ãŒãããåçŽã«ãããã¯ã€ãããåçŽãªããã°ã©ã ã®ã³ãŒãäŸã瀺ããŸããã æ»æã®å®è£ ã«äœ¿çšã§ããJSã¹ã¯ãªããã®äŸãããã€ãåãäžããŸããã ããã°ã©ã ã®äŸã以äžã®ã¹ã¯ãªãŒã³ã·ã§ããã«ç€ºããŸãããã£ã«ã¿ãŒãããã·ãŒã±ã³ã¹ãã¿ã°ã®éã«è¡šç€ºãããŸã
<p></p>
ããã°ã©ã ã³ãŒãïŒ
2ã€ã®ã©ã€ãã©ãªãäžç·ã«äœ¿çšããçµæã®çµè«ïŒ
ãããŠãäœããã®çç±ã§çªç¶ãµãŒãããŒãã£ã®ã©ã€ãã©ãªã䜿çšããããªãå Žåã¯ããããã«äœ¿ãããã«ã¯ãhtml /ãã³ãã¬ãŒãããã±ãŒãžã«å«ãŸãã䟿å©ãªæ©èœãããã€ããããŸãã
â¢funcHTMLEscapeïŒw io.Writerãb []ãã€ãïŒã¯ãæœåšçã«å±éºãªæåããšã¹ã±ãŒãã·ãŒã±ã³ã¹ã§çœ®ãæããŠãããŒãžã§ã³bãwã«éä¿¡ããŸãã
â¢funcHTMLEscapeStringïŒs stringïŒstringã¯ãæœåšçã«å±éºãªæåããšã¹ã±ãŒãã·ãŒã±ã³ã¹ã«çœ®ãæããŠããŒãžã§ã³sãè¿ããŸãã
â¢funcHTMLEscaperïŒargs ... interface {}ïŒæååã¯ãæœåšçã«å±éºãªæåããšã¹ã±ãŒãã·ãŒã±ã³ã¹ã«çœ®ãæããŠãå€ãã®åŒæ°ã®æååã圢æããŸãã
ãŸããå ¥åãã©ã¡ãŒã¿ãŒã¯Sanitizingãç°¡åã«ãã¯ãªã¢ãã§ããŸãã ãã®ã©ã€ãã©ãªã®githubã«ã¯ãåãOWASPããã®å ¥åã䜿çšããããªãå®å šãªãã¹ãããããŸãã
ã¯ãªãã¯ãžã£ããã³ã°
ClickjackingãšããŠç¥ãããæ»æããããŸãã ã¯ãªãã¯ãžã£ããã³ã°æ»æã«ãããããã«ãŒã¯ã蚪åè ã«ä»£ãã£ãŠã被害è ã®ãµã€ããã¯ãªãã¯ããããšãã§ããŸããããã¯ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ã®ãªãããŸããšãåŒã°ããŸãã ãããã£ãŠãããã«ãŒã¯ããŸããŸãªã·ããªãªãèãåºããããšãã°ãæ°åã¯ãªãã¯ããã ãã§ãã¢ãã€ã«ãã³ã¯ããã¢ã«ãŠã³ãã«ééã§ããŸãã å¥åŠãªããšã«ã DBOãªã¢ãŒããã³ãã³ã°ã·ã¹ãã ã§ãåæ§ã®è匱æ§ãèŠã€ãã£ãŠããŸãã ããã³ãã³ã°ã·ã¹ãã ã¯éåžžã®Webã¢ããªã±ãŒã·ã§ã³ãããã¯ããã«åªããä¿è·ãå¿ èŠãšæãããŸãã
ãŸããä¿è·ã®ããã«ããµãŒããŒããã®åå¿çã«X-Frame-OptionsããããŒãæ·»ä»ããããšããå§ãããŸãã çŸåšãææ°ã®ãã©ãŠã¶ã¯ãã¹ãŠX-Frame-OptionsããããŒããµããŒãããŠããŸãã ããŒãžããã¬ãŒã ã§éãããŠããå ŽåãããŒãžã®è¡šç€ºãæå¹ãŸãã¯ç¡å¹ã«ããŸãã ããããŒã«ã¯3ã€ã®æå³ããããŸãã
â¢SAMEORIGIN-ãã¬ãŒã ã§éãããããã¥ã¡ã³ãã®ã¬ã³ããªã³ã°ã¯ãæäžäœã®ããã¥ã¡ã³ããåããã¡ã€ã³ããã®ãã®ã§ããå Žåã«ã®ã¿å®è¡ãããŸãã
â¢æåŠ-ãã¬ãŒã å ã®ããã¥ã¡ã³ãã®ã¬ã³ããªã³ã°ã¯çŠæ¢ãããŠããŸãã
â¢ALLOW-FROMãã¡ã€ã³-ãã®ãã¡ã€ã³ããã®å€éšããã¥ã¡ã³ãã®å Žåãã¬ã³ããªã³ã°ãèš±å¯ããŸãïŒSafariãFirefoxã§ã¯ãµããŒããããŠããŸããïŒã
Goã§ã®å¿çããããŒã®è¿œå ã®å®è£ äŸã
Secureã¯ããµãŒãã¹ã®å®å šãªãã©ã¡ãŒã¿ãŒã䟿å©ã«èšå®ããããã®å°ããªã¬ã€ã€ãŒã§ãã Secureã¯ãæšæºããã±ãŒãžnet / httpã ãã§ãªããå€æ°ã®ãã¬ãŒã ã¯ãŒã¯ã§ãæ©èœããŸãã
SQLã€ã³ãžã§ã¯ã·ã§ã³
SQlã€ã³ãžã§ã¯ã·ã§ã³ã¯ãã¯ãšãªãžã®ä»»æã®SQLã³ãŒãã®å°å ¥ã«åºã¥ããŠãããŒã¿ããŒã¹ãæäœãããµã€ãããã³ããã°ã©ã ããããã³ã°ããæãäžè¬çãªæ¹æ³ã®1ã€ã§ãã
Goã§ã¯ããã©ã¡ãŒã¿ãŒåãããã¯ãšãªããŸãã¯ä»ã«æºåãããåŒãšåŒã°ãããã®ã䜿çšã§ããŸãã SQLã€ã³ãžã§ã¯ã·ã§ã³ã«é¢ããããã€ãã®åé¡ãåé¿ããã®ã«åœ¹ç«ã¡ãŸãã
æ£èŠè¡šçŸãã£ã«ã¿ãªã³ã°ã䜿çšããããšãã§ããŸãã ãã®å Žåãidãšuidã®æ°åã®ã¿ãå«ãäœæ¥ãªã³ã¯ã䜿çšããŸãã Goã§ãããã©ã®ããã«çŸããè¡ããã®äŸã§ãã
ç¹å®ã®æåã®ãšã¹ã±ãŒãã䜿çšããŸãã ããšãã°ãäžéåŒçšç¬Šã
ããã°ã©ã ã®åºåã æåã»ããæååã»ãã«çœ®ãæããããŠããããšãããããŸãã
ãã ããsql-injectionãå®è£ ãããšãã¯ãåŒçšç¬Šãä»ããå¿ èŠããªãããšãå¿ããªãã§ãã ããã å€æ°vuln1ã«ã¯ãã®è¡ãå«ãŸããŠããã ãã§ãEscapeStringé¢æ°ãééããŠããŸã£ããå€åããŸããã
SafeSQL
SafeSQLã¯Goçšã®éçã³ãŒãã¢ãã©ã€ã¶ãŒã§ãããSQLã€ã³ãžã§ã¯ã·ã§ã³ãèŠã€ããããšãã§ããŸãã
ãããã«
Goã¯ããªãæ°ããããã°ã©ãã³ã°èšèªã§ãããšããäºå®ã«ãããããããã³ãã¥ããã£ã¯æ¥éã«æé·ããŠãããã»ãŒãã¹ãŠã®ãããžã§ã¯ãã«èŠãããåºæ¬çãªãœãªã¥ãŒã·ã§ã³ãå®è£ ããŠããŸãã Webã¢ããªã±ãŒã·ã§ã³ã»ãã¥ãªãã£ã«åºã¥ããœãªã¥ãŒã·ã§ã³ãå«ã¿ãŸãã ãã®èšäºã§ã¯ãSQLã€ã³ãžã§ã¯ã·ã§ã³ãCSRFãXSSãã¯ãªãã¯ãžã£ããã³ã°ãåé¿ããæ¹æ³ãæ€èšããŸããã äžèšã®æ¹æ³ã¯ãWebã¢ããªã±ãŒã·ã§ã³ã®å®å šãªã»ãã¥ãªãã£ã®äžèœè¬ã§ã¯ãããŸããã ããããæ å ±ã»ãã¥ãªãã£ã«é¢é£ããåºæ¬çãªåé¡ã®ã»ãšãã©ã解決ããã®ã«åœ¹ç«ã¡ãŸãã
äžå€æåŠ
https://learn.javascript.ru/csrf
https://nvisium.com/blog/2014/11/26/developing-secure-applications-with/
https://astaxie.gitbooks.io/build-web-application-with-golang/content/en/09.1.html
https://learn.javascript.ru/clickjacking
http://0xdabbad00.com/2015/04/18/go_code_auditing/
http://dghubble.com/blog/posts/json-web-tokens-and-go/