੬ऑੑͱԿ͔
w ίϯϐϡʔλͷ04ιϑτΣΞʹ͓͍ͯɺϓϩάϥϜͷෆ۩߹ઃܭ্ͷϛε͕ݪ
Ҽͱͳͬͯൃੜͨ͠ใηΩϡϦςΟ্ͷܽؕ
w IUUQXXXTPVNVHPKQNBJO@TPTJLJKPIP@UTVTJOTFDVSJUZCBTJDSJTL
IUNM
w ཁѱ༻Մೳͳόά
w 8FCαΠτͷ༰Λॻ͖͑Δ
w ൿಗ͖͢ใͷ࿙Ӯ
w νʔτɺΓ͢·͠ͳͲ
w ଞਓ͘͠αʔϏεʹةΛՃ͑Δ͜ͱ͕Ͱ͖Δ
w ৴༻ΛࣦͬͨΓɺۚમతଛࣦͷิరͳͲ
Slide 3
Slide 3 text
എܠ
w 8FCશظ
w ͋ΒΏΔ͜ͱ͕8FCͰΓऔΓ͞Ε͍ͯΔ
w ෳࡶԽ͢Δ8FC
w ཚཱ͢ΔϑϨʔϜϫʔΫ
w &MFDUSPO3FBDU/BUJWFͷొ
w Ռͨͯ͠ੈͷதͷ8FCΞϓϦέʔγϣϯ҆શ͔ʁ
Slide 4
Slide 4 text
എܠ
w 8FCΞϓϦέʔγϣϯϑϨʔϜϫʔΫϒϥβɺ8FCͷ༷ͳ
ͲʹΑΔอޢ
w ࣗ໌ͳͷ͍Ͱ͘ΕΔ 944
42-*OKFDUJPO
$43'
w શ෦͍Ͱ͘ΕΔΘ͚Ͱͳ͍
w ϨʔϧΛ֎ΕΔͱ੬ऑੑΛ࡞ΓࠐΜͰ͠·͍͕ͪ
w ੈͷதͷ8FCΞϓϦέʔγϣϯͷඪ४͍
Slide 5
Slide 5 text
ηΩϡΞͳΞϓϦέʔγϣϯΛ࡞ΔͨΊʹ
w ੬ऑੑΛΔ
w ͜ͷػೳΛ࣮͢Δͱ͖ɺ͜ͷ੬ऑੑʹؾΛ͚ͭΔ
w ߈ܸऀઢͰ࣮ςετΛߦ͏
w ͜ͷೖྗΛೖΕΔͱେৎͩΖ͏͔ʁ
w ݖݶదʹઃఆ͞Ε͍ͯΔͩΖ͏͔ʁ
Slide 6
Slide 6 text
ࠓͷΰʔϧ
w ੬ऑͳ8FCΞϓϦέʔγϣϯͷஅΛ௨ͯ͠
˖ וך歗堣腉דוְֲ腚䓲䚍ָ欰ַׄ濼
˖ 腚䓲䚍ך⾱椚濼ծ䕦갟罋ִ
˖ 呎劤涸㼎瘻ה⥂ꤹ涸㼎瘻חאְג㷕ע
Slide 7
Slide 7 text
ҙࣄ߲
˖ 盖鱥㢩ך،فٔ؛٦ءّٝח窫㼎余䷼׃זְ
w #VH#PVOUZ੍
w IBDLFSPOFɿIUUQTXXXIBDLFSPOFDPN
w $ZCP[V੬ऑੑใ੍ۚ
w ͠ݟ͚ͭͨΒ*1"ʹใࠂ͠Α͏
w IUUQTXXXJQBHPKQTFDVSJUZWVMOSFQPSU
Slide 8
Slide 8 text
8FC੬ऑੑجૅ
Slide 9
Slide 9 text
)551
(&5QBUIUPJOEFYIUNM
)5510,
ϦΫΤετ
Ϩεϙϯε
Slide 10
Slide 10 text
)551௨৴ΛݟΔ
w ৭ʑखஈ͋Γ·͢
w %FW5PPMTʢ։ൃऀπʔϧʣ͕खܰ
w ϩʔΧϧϓϩΩγ
w 08"41;"1
'JEEMFS
#VSQ4VJUF
w ͜͜Ͱ#VSQ4VJUFΛ͍·͢
Slide 11
Slide 11 text
#VSQ4VJUF
ΫϥΠΞϯτϚγϯ
ϒϥβ #VSQ4VJUF
8FCΞϓϦέʔγϣϯ
ɾ௨৴ͷه
ɾϦΫΤετϨεϙϯεͷվม
w ੬ऑੑஅπʔϧϩʔΧϧϓϩΩγ
w ϩʔΧϧϓϩΩγΛ͏͜ͱͰϦΫΤετͷվมʢ੬ऑੑஅʣ
͕༰қʹͳΔ
Slide 12
Slide 12 text
怴统
#VSQד)551鸐⥋鋅״ֲ
Slide 13
Slide 13 text
)551௨৴ΛݟΑ͏
w #VSQ4VJUFͰ)551௨৴ΛݟͯΈ·͠ΐ͏
w ຊߨٛͰϒϥβ'JSFGPYΛલఏʹਐΊ͍͖ͯ·͢
w ࣄલ՝ͷ8FCΞϓϦέʔγϣϯΛࡐͱͯ͠ਐΊ·͢
w IUUQTNJOJDBNQUVUPSJBMIFSPLVBQQDPN
#VSQͰ௨৴ΛݟΔ
w 'JSFGPYͰIUUQTNJOJDBNQUVUPSJBMIFSPLVBQQDPNʹΞΫ
ηε
'PSXBSEͰϦΫΤετΛૹ৴
*OUFSDFQUJTPOʹͳ͍ͬͯΔؒ
ϦΫΤετ͕Ωϟϓνϟ͞ΕΔ
Slide 17
Slide 17 text
#VSQͰ௨৴ΛݟΔ
w աڈͷ௨৴ϩάIJTUSPZλϒʹ͋Δ
Slide 18
Slide 18 text
怴统
腚䓲䚍鏺倖ثُ٦زٔ،ٕ
Slide 19
Slide 19 text
8FCΞϓϦέʔγϣϯஅͬͯʁ
w 8FCΞϓϦέʔγϣϯʹରͯ͠߈ܸऀࢹͰ੬ऑੑΛݟ͚ͭΔ
w ରͷѲɺݟੵΓ
˖ خ٦ٕד鏺倖׃אאծخ٦ٕדכ嗚⳿♶〳腉ז鏺倖䩛⹛ד
˖ 䕦갟װⱄ植倯岀זוחאְג㜠デ剅⡲䧭
w ݟΔ߲
w IUUQTJFSBFDPKQTFSWJDFXFCBQQMJDBUJPO
w ͜͜ʹهࡌ͕ͳ͍ͷ֬ೝ͠·͢
Slide 20
Slide 20 text
੬ऑੑஅνϡʔτϦΞϧ
w ϢʔβʔొɺϩάΠϯɺϙετͷߘɺฤूɺআͳͲΛͬͯΈΑ͏
w ֤छૢ࡞Λͨ͠ͱ͖ʹ
w ͲΜͳϝιουΛ͍ͬͯΔ͔ʁ
w ͲΜͳύϥϝʔλΛૹ৴͍ͯ͠Δ͔ʁύϥϝʔλͷҙຯʁ
w ͲΜͳϨεϙϯε͕ฦ͍ͬͯΔ͔ʁ
w ͳͲʹ͠Α͏
w &Y
ϩάΠϯͰ1045ϝιουΛͬͯɺೝূΛ͍ͯ͠ΔɻϦμΠϨΫτͰϩάΠϯޙ
τοϓʹϦμΠϨΫτ͞ΕΔɻ
˖ 兛媮⢪欽׃גְػأٙ٦سװꅾ銲ז䞔㜠כ剅ֹ鴥תזְ״ֲח孡אֽגְֻׁ
Slide 21
Slide 21 text
੬ऑੑஅνϡʔτϦΞϧ
w ݖݶ֎ૢ࡞
w ηογϣϯΛݟ͍ͯͳ͍ͷͰύϥϝʔλΛมߋ͢ΔͱɺҙͷϢʔβʔͰϙετΛ
࡞Ͱ͖Δ
w 944
w ѱҙ͋Δ+BWB4DSJQUͷ࣮ߦِใͷදࣔ
w $43'
w ඃऀͷݖݶͰ֬ఆॲཧ͕࣮ߦ͞ΕΔ
w 42-ΠϯδΣΫγϣϯ
w 42-จͷෆਖ਼ͳվมʹΑΔใ࿙͍͑ͳͲ
Slide 22
Slide 22 text
੬ऑੑஅνϡʔτϦΞϧ
˖ 埄ꣲ㢩乼⡲
˖ إحءّٝ鋅גְזְךדػًٓ٦ة㢌刿ׅהծ⟣䠐ךِ٦ؠ٦דهأز
⡲䧭דֹ
w 944
w ѱҙ͋Δ+BWB4DSJQUͷ࣮ߦِใͷදࣔ
w $43'
w ඃऀͷݖݶͰ֬ఆॲཧ͕࣮ߦ͞ΕΔ
w 42-ΠϯδΣΫγϣϯ
w 42-จͷෆਖ਼ͳվมʹΑΔใ࿙͍͑ͳͲ
Slide 23
Slide 23 text
ݖݶ֎ૢ࡞
w ϙετߘը໘
w τοϓʼOFXQPTUʼDSFBUFQPTU
w QPTUTʹ1045ϦΫΤετ
w ύϥϝʔλʹ
ߘϑΥʔϜͷ༰͕ͦΕͧΕύϥϝʔλʹؚ·Ε͍ͯΔ
Ͳ͏࣮͢Δ͖͔
w $PPLJFͳͲͷηογϣϯใ͔ΒϢʔβʔΛผ͢Δ
$PPLJFTFTTJPO@JEBCDE
QPTU<UJUMF>QPTU<VTFS@JE> TFTTJPO@JE͕BCDEͳͷ
Ϣʔβʔͩͳ
VTFS@JE͕ͷϢʔβʔͰ࡞
w ࣗͰ࣮͠ͳͯ͘ϑϨʔϜϫʔΫʹDVSSFOU@VTFSͳͲͷ
ϝιουɺϔϧύʔ͕ଘࡏ͢ΔͷͰͦΕΛ͏
Slide 30
Slide 30 text
ηογϣϯ*%ͰؾΛ͚ͭΔ͜ͱ
w ηογϣϯ*%ୈऀ͕༧ଌෆՄೳͳͷͰ͋Δ͜ͱ
w ηογϣϯ*%Λ63-ʹؚΊͳ͍
w IUUQTFYBNQMFDPNNZQBHF KTFTTJPOJEBCDEFGH
w 3FGFSFSʹΑͬͯϦϯΫઌͷ63-ૹ৴͞ΕΔ
w ϩάΠϯޭޙʹηογϣϯ*%Λ৽͘͠ൃߦ͢Δ
w 4FTTJPO'JYBUJPO ηογϣϯݻఆԽ߈ܸʣ
w )5514௨৴Ͱར༻͢Δ߹TFDVSFଐੑΛ͚ͭΔ
w )551௨৴Ͱૹ৴͠ͳ͍Α͏ʹ͢Δ͜ͱͰ౪ௌʹΑΔෆਖ਼औΛ͙
Slide 31
Slide 31 text
੬ऑੑஅνϡʔτϦΞϧ
w ݖݶ֎ૢ࡞
w ηογϣϯΛݟ͍ͯͳ͍ͷͰύϥϝʔλΛมߋ͢ΔͱɺҙͷϢʔβʔͰϙετΛ
࡞Ͱ͖Δ
˖ 944
˖ 䝤䠐֮+BWB4DSJQUך㹋遤װ⩝䞔㜠ך邌爙
w $43'
w ඃऀͷݖݶͰ֬ఆॲཧ͕࣮ߦ͞ΕΔ
w 42-ΠϯδΣΫγϣϯ
w 42-จͷෆਖ਼ͳվมʹΑΔใ࿙͍͑ͳͲ
Slide 32
Slide 32 text
944
w ϙετৄࡉը໘
w τοϓʼ4IPX
w QPTUT\QPTU@JE^
w Ϣʔβʔͷߘ͕)5.-ʹө͞ΕΔ
w λΠτϧɺຊจ
Slide 33
Slide 33 text
944
w Ϣʔβʔͷೖྗ༰͕)5.-ͱͯ͠ө͞ΕΔͱ͖ɺ944ʢΫϩ
εαΠτεΫϦϓςΟϯάʣͱݺΕΔ੬ऑੑͷՄೳੑ͕͋Δ
w ։ൃऀͷҙਤ͠ͳ͍ܗͰ)5.-+BWB4DSJQUΛೖ͞ΕΔͨΊɺ
ѱҙͷ͋Δ+BWB4DSJQU࣮ߦͳͲʹͭͳ͕Δ
߈ܸ༻+BWB4DSJQUΛࠐΉ
ѱҙ͋ΔεΫϦϓτ
ຒΊࠐ·ΕͨϖʔδΛӾཡ͢Δ͜ͱͰ
ඃऀͷϒϥζ্Ͱ+BWB4DSJQU͕࣮ߦ
944ͷӨڹ
Өڹɿ+BWB4DSJQUדדֹֿה͑944דדֹֿה
w ηογϣϯΛ౪·ΕͯΓ͢·͠ඃʹ߹͏
w ෆਖ਼ͳ+BWB4DSJQU͕ಈ࡞͠ɺΞϓϦέʔγϣϯͷػೳΛѱ༻͞ΕΔ
w ِͷϑΥʔϜΛ࡞Γग़͢ͳͲͯ͠ɺϑΟογϯάʹ߹͏
w ѱ࣭ͳϖʔδϦμΠϨΫτ
ൃੜՕॴɿ)5.-+BWB4DSJQUΛੜ͍ͯ͠Δͱ͜Ζ
Slide 36
Slide 36 text
944ͷݪཧ
w )5.-ੜ࣌ʹೖ͞ΕͨʮʼʯʮʻʯΛΤεέʔϓͤͣʹग़
ྗͨͨ͠Ίʹɺ)5.-λάͱͯ͠ѻΘΕΔɻ
// $str = alert(1)
alert(1)
// $str = ">alert(1)
alert(1) />
Slide 37
Slide 37 text
944ͷݕࠪํ๏
w BMFSUΛग़͢
">alert(1)
'; alert(1); //
w )5.-͕ૠೖՄೳ͔
">XSS
">
XSS
w %0.#BTFE944
var el = document.getElementById("item")
el.innerHTML = foo; // foo = alert(1)
Slide 38
Slide 38 text
944ͷجຊతͳରࡦ
w جຊతͳରࡦͱͯ͠ҎԼͷ)5.-ग़ྗ࣌ʹ)5.-ϝλΩϟϥΫλΛΤεέʔϓ͢Δ
˖ ̔MU
˖ ̔HU
˖ ̔BNQ
˖ ̔RVPU
˖ ̔
w ࠷ۙͷϑϨʔϜϫʔΫʢςϯϓϨʔτΤϯδϯʣͰࣗಈͰΤεέʔϓ͞ΕΔ
w Τεέʔϓ͠ͳ͍߹໌ࣔతʹߦ͏ඞཁ͕͋Δʢٯʹ࡞ΓࠐΈʹ͍͘ʣ
# Rails(erb)
<% raw @post.body %>
Slide 39
Slide 39 text
944ରࡦେม
KBWBTDSJQUBMFSU
BISFGKBWBTDSJQUBMFSU
IUUQͱIUUQTʹͷΈ
ݶఆ͢ΔͳͲͷରࡦ͕ඞཁ
w Α͘ࡐʹ͋͛ΒΕΔͷ͕63-ग़ྗ
w ͜ͷ͋ͨΓϑϨʔϜϫʔΫʹΑͬͯରࡦ͞Εͳ͍͜ͱ͕ଟ͍ͷ
Ͱɺ։ൃऀ͕ؾΛ͚ͭΔඞཁ͕͋Δɻ
Slide 40
Slide 40 text
3BJMTͩͱ
w ҆ʹग़ྗͯ͠μϝɻIUUQͱIUUQTͳͲͷΈʹ੍ݶΛ͔͚Δɻ
w KBWBTDSJQUEBUBͳͲΛڐՄ͠ͳ͍Α͏ʹϗϫΠτϦετͰ੍ݶ
// Bad
<%= link_to link, link %>
<%= link %>
// Good
<%= sanitize link_to link, link %>
w Τεέʔϓͷ࣮
w IUUQTHJUIVCDPNSBJMTSBJMTCMPCNBTUFSBDUJWFTVQQPSUMJC
BDUJWF@TVQQPSUDPSF@FYUTUSJOHPVUQVU@TBGFUZSC
w IUUQBQJSVCZPOSBJMTPSHDMBTTFT"DUJPO7JFX)FMQFST4BOJUJ[F)FMQFSIUNM
Slide 41
Slide 41 text
944ରࡦେม
w έʔεόΠέʔεʹͳΓ͕ͪ
w ಛఆͷ)5.-λάϢʔβʔೖྗ$44ΛڐՄ͍ͨ͠
w TWHPOMPBEBMFSU
w QTUZMFYFYQSFTTJPO BMFSU
w .BSLEPXOͦͷଞͷϚʔΫΞοϓݴޠΛ)5.-ϨϯμϦϯά͍ͨ͠
w KBWBTDSJQUBMFSU
w IUUQTIBDLFSPOFDPNSFQPSUT
w ҆શͳΣϒαΠτͷ࡞ΓํΫϩεαΠτεΫϦϓςΟϯά
w IUUQTXXXJQBHPKQpMFTQEGQBHF
w %0.ϕʔε944ରࡦνʔτγʔτ
w IUUQTKQDFSUDDHJUIVCJP08"41EPDVNFOUT$IFBU4IFFUT%0.CBTFE9441SFWFOUJPOIUNM
">
[example.com](javascript:alert(1))
Slide 42
Slide 42 text
؇తରࡦ
w ੬ऑੑଘࡏ͢Δ͚Ͳɺѱ༻͕͍͠Ϩϕϧʹམͱ͠ࠐΉ
˖ $PPLJFךIUUQPOMZ㾩䚍
w +BWB4DSJQU͔Β$PPLJFΛ৮Εͳͯ͘͠ɺηογϣϯϋΠδϟοΫ͔ΒकΔ
˖ 99441SPUFDUJPOقحت٦
w ϒϥβͷ944ݕɾࢭػೳ
˖ $41$POUFOU4FDVSJUZ1PMJDZ
w 944Λܰݮ͢ΔͨΊʹઃܭ͞ΕͨΈ
w ࢦఆ͞ΕͨεΫϦϓτҎ֎࣮ߦͤ͞ͳ͍
Slide 43
Slide 43 text
੬ऑੑஅνϡʔτϦΞϧ
w ݖݶ֎ૢ࡞
w ηογϣϯΛݟ͍ͯͳ͍ͷͰύϥϝʔλΛมߋ͢ΔͱɺҙͷϢʔβʔͰϙετΛ
࡞Ͱ͖Δ
w 944
w ѱҙ͋Δ+BWB4DSJQUͷ࣮ߦِใͷදࣔ
˖ $43'
˖ 鄃㹱罏ך埄ꣲד然㹀Ⳣ椚ָ㹋遤ׁ
w 42-ΠϯδΣΫγϣϯ
w 42-จͷෆਖ਼ͳվมʹΑΔใ࿙͍͑ͳͲ
Slide 44
Slide 44 text
$43'
w ίϝϯτߘը໘
w τοϓʼTIPXʼ$SFBUF$PNNFOU
w QPTUT\QPTU@JE^
w DPNNFOUTʹ1045ϦΫΤετ
w Ϣʔβʔʹඥ͍ͨίϝϯτͷߘ͕͞ΕΔ
ݪҼ
w 8FCͷಛੑΛ׆͔ͨ͠੬ऑੑ
w GPSNͷૹ৴ઌͲͷυϝΠϯͰ0,
w FWJMDPNͷϖʔδ͚ͩͲFYBNQMFDPNʹૹ৴Ͱ͖Δ
w ͦͷࡍɺ$PPLJFରͷαΠτʹࣗಈతʹૹ৴͞ΕΔ
w ਖ਼نʢར༻ऀ͕ҙਤͨ͠ʣϦΫΤετͰ͋Δ͜ͱΛ֬ೝ͢Δ
w $43'τʔΫϯͷຒΊࠐΈ
w 3FGFSFSͷνΣοΫʢ߹ʹΑͬͯૹ৴͞Εͳ͍ͷͰʣ
Slide 48
Slide 48 text
$43'τʔΫϯ
w ରࡦ͕ඞཁͳϖʔδʹୈऀ͕Γಘͳ͍τʔΫϯΛຒΊΔ
w ϦΫΤετதʹؚ·ΕΔτʔΫϯ͕ਖ਼͍͔͠ΛνΣοΫ͢Δ
w ݕࠪ࣌ɺϦΫΤετʹτʔΫϯࣗମ͚ͳ͍ɺ͚ۭͩʹ͢Δͱ͍ͬͨνΣοΫΛΔ
Slide 49
Slide 49 text
$43'ରࡦ
w 3BJMTͳͲͷ࠷ۙͷϑϨʔϜϫʔΫͰσϑΥϧτͰ༗ޮ
w ϑΥʔϜ࡞࣌ʹࣗಈͰຒΊࠐ·ΕɺνΣοΫͯ͘͠ΕΔ
w IUUQTHJUIVCDPNSBJMTSBJMTCMPCNBTUFSBDUJPOQBDL
MJCBDUJPO@DPOUSPMMFSNFUBM
SFRVFTU@GPSHFSZ@QSPUFDUJPOSC
w IUUQUBLBHJIJSPNJUTVKQEJBSZIUNM
Slide 50
Slide 50 text
ͱ͍͑ɺ࣌
w ࣌"KBY 9)3
w 3BJMTͰ+BWB4DSJQUͬͯ1045͍ͨ͠ΜͰ͕͢
<% form_for @post, remote: true do |f| %>
w NFUBλάͷ$43'τʔΫϯΛ9$43'5PLFOϔομʹηοτ
w IUUQTHJUIVCDPNSBJMTKRVFSZSBJMTCMPCNBTUFSWFOEPS
BTTFUTKBWBTDSJQUTKRVFSZ@VKTKT-
X-CSRF-Token: KvDjn0XOpeK2dXiJ0sKXMzFYmnfQrkoY...
w %KBOHPIUUQTEPDTEKBOHPQSPKFDUDPNFOSFGDTSGBKBY
Slide 51
Slide 51 text
ͱ͍͑ɺ࣌41"
w Ͳ͏ͬͯ$43'ରࡦ͢Ε͍͍Ͱ͔͢
w ಠࣗϔομΛ্͚ͭͨͰɺ015*0/4ʹԠ͠ͳ͍
w ࣮ࡍͷॲཧͷલʹ1SFqJHIU͕ඈͿ
w +85Ͱೝূͯ͠ϔομͰεςʔτϨεͳঢ়ଶͰ
w MPDBM4UPSBHFʹอଘ͢Δ͜ͱ͕ଟ͍
͕ɺવIUUQ0OMZͷΑ͏ͳػೳແ͍ͷ
Ͱؾ߹Ͱ944Λ௵͞ͳ͚ΕͳΒͳ͍
w IUUQEIBUFOBOFKQIBTFHBXBZPTVLFQ
w 0SJHJO͕ਖ਼͍͠63-Ͱ͋Γɺ9'SPN͕͋Δ͜ͱ
w 0SJHJO͕ਖ਼͍͠9)33FRVFTU8JUI͕͋Δ
IUUQTXXXPXBTQPSHJOEFYQIQ$SPTT4JUF@3FRVFTU@'PSHFSZ@ $43'
@1SFWFOUJPO@$IFBU@4IFFU1SPUFDUJOH@3&45@4FSWJDFT@6TF@PG@$VTUPN@3FRVFTU@)FBEFST
Slide 52
Slide 52 text
੬ऑੑஅνϡʔτϦΞϧ
w ݖݶ֎ૢ࡞
w ηογϣϯΛݟ͍ͯͳ͍ͷͰύϥϝʔλΛมߋ͢ΔͱɺҙͷϢʔβʔͰϙετΛ࡞
Ͱ͖Δ
w 944
w ѱҙ͋Δ+BWB4DSJQUͷ࣮ߦِใͷදࣔ
w $43'
w ඃऀͷݖݶͰ֬ఆॲཧ͕࣮ߦ͞ΕΔ
˖ 42-؎ٝآؙؑءّٝ
˖ 42-俑ך♶姻ז何㢌ח״䞔㜠怩ְִזו
Slide 53
Slide 53 text
42-ΠϯδΣΫγϣϯ
w τοϓʼ4FBSDI
w QPTUT VUG&$UJUMF\ݕࡧϫʔυ^
w λΠτϧͰݕࡧ
w ʮςετʯʮςʯɺʮεʯͳͲͰڍಈΛ֬ೝ
SELECT * FROM post WHERE title LIKE '%#{title}%'
Slide 54
Slide 54 text
42-ΠϯδΣΫγϣϯ
ൃੜՕॴɿ42-ݺͼग़͠Λߦ͏Օॴ
Өڹ
w ҙਤ͠ͳ͍ܗͰ42-จ͕վม͞ΕΔ
w σʔλϕʔε͕ෆਖ਼ʹૢ࡞͞ΕΔ
w σʔλϕʔε͔Βใऔɺվ᜵ͳͲ
w 3%#4ͷػೳΛར༻ͨ͠ҙϑΝΠϧͷಡΈॻ͖ɾ࣮ߦ
Slide 55
Slide 55 text
42-ΠϯδΣΫγϣϯ
SELECT * FROM post WHERE title LIKE '%#{title}%'
// #{title} = "title"
SELECT * FROM post WHERE title LIKE 'title'
// #{title} = "O'Reilly"
SELECT * FROM post WHERE title LIKE 'O'Reilly'
// #{title} = "title'; DELETE FROM post;-- "
SELECT * FROM post WHERE title LIKE 'title'; DELETE FROM post;--
OBNFVTFS03QBTT
4&-&$5'30.VTFS
8)&3&OBNFVTFS03"/%QBTTXPSE
-PHJO4VDDFTT
Slide 56
Slide 56 text
42-ΠϯδΣΫγϣϯ
w ҎԼͷจࣈྻͰݕࡧʢҰߦʣ
w VTFSςʔϒϧ͔ΒϢʔβʔͷใΛऔͰ͖Δ
title%') UNION SELECT
id,email,encrypted_password,NULL,NULL,NULL,NULL FROM users;--
Slide 57
Slide 57 text
࣮ࡍͷஅ
w 42-ΠϯδΣΫγϣϯͦͷੑ্࣭ɺσʔλϕʔεͷফڈͳͲͷՄೳੑ
͕͋ΔͷͰɺ৻ॏʹߦΘͳ͚ΕͳΒͳ͍
w ؾܰʹ8FCαΠτͰࢼ͞ͳ͍ํ͕͍͍
w 42-ΠϯδΣΫγϣϯ͕͋Δͱ͔Εྑ͍ͷͰɺग़དྷΔݶΓ҆શͳํ
๏ͰݕࠪΛߦ͏
w 5SVF'BMTF
w ԋࢉɺจࣈྻ࿈݁
w TMFFQͳͲൺֱత҆શͳؔ
Slide 58
Slide 58 text
ʢͰ͖Δ͚ͩʣ҆શͳݕࠪ
w ʮ"/%
ʯͰݕࡧ
w ʮ"/%
ʯͰݕࡧ
SELECT * FROM posts WHERE (title = 'hoge' AND 1=1)--
SELECT * FROM posts WHERE (title = 'hoge' AND 1=2)--
5SVFͳͷͰ
ಉ͡ݕࡧ݁Ռ͕ฦΔ
'BMTFͳͷͰ
ࣜશମ͕'BMTFͱͳΓ
ԿฦΒͳ͍
Slide 59
Slide 59 text
w จࣈྻ࿈݁
w IUUQTFYBNQMFDPN TFBSDIUFccTU
w ʮUFTUʯͱʮUF]]TUʯͰಉ͡Ϩεϙϯε͕ฦΔ͜ͱΛ͔֬ΊΔ
SELECT * FROM posts WHERE (title = 'te' || 'st')
w ΤϥʔͰ֬ೝ͢Δ
w IUUQTFYBNQMFDPN TFBSDIˠΤϥʔ
w IUUQTFYBNQMFDPN TFBSDIˠ0,
SELECT * FROM posts WHERE (title = ''') # Syntax Error
SELECT * FROM posts WHERE (title = '''')
ʢͰ͖Δ͚ͩʣ҆શͳݕࠪ
Slide 60
Slide 60 text
SELECT * FROM posts WHERE (id = 2+1)
w
w IUUQTFYBNQMFDPNQPTU
w ʮʯʮʯͱ͢Δ͜ͱͰಉ͡Ϩεϙϯε͕ฦΔ͜ͱΛ͔֬ΊΔ
w TMFFQ
w IUUQTFYNBQMFDPN TFBSDIUFTU
w UFTU"/% 4&-&$5'30. 4&-&$5 4-&&1
B
w ϦΫΤετΛૹ৴ͯ͠ඵޙʹϨεϙϯε͕ฦΔ͜ͱΛ͔֬ΊΔ
SELECT * FROM posts WHERE (title = 'test' AND (SELECT * FROM
(SELECT (SLEEP(10)))a))--
ʢͰ͖Δ͚ͩʣ҆શͳݕࠪ
Slide 61
Slide 61 text
ରࡦ
w 42-จͷΈཱͯ੩తϓϨʔεϗϧμͰ࣮͢Δ
w ʮʁʯʹՄมͷύϥϝʔλʢมͳͲʣ͕ຒΊࠐ·ΕΔ
w %#Ͱ42-จͷίϯύΠϧ͕ߦΘΕɺ͕όΠϯυ͞ΕΔ
SELECT * FROM posts WHERE (title = ?)
w 03.ͷػೳΛదʹ͍ɺจࣈྻ݁߹ͳͲ͠ͳ͍ͷ͕మଇ
w 3BJMTͳͲͷϑϨʔϜϫʔΫ ͱ͍͏ΑΓ03.ʣ͕ϝιουΛఏڙ͍ͯ͠Δ
w ࣗͰ42-Λจࣈྻ࿈݁͢Δඞཁͳ͍
w ٯʹෳࡶͳΫΤϦͰͳ͍ͷʹจࣈྻ࿈݁͢Δͱ͖͓͔͍͠ͱࢥͬͨํ͕͍͍
Post.where(title: title)
# SELECT * FROM posts WHERE (title = 'title');
Slide 62
Slide 62 text
3BJMTͰͷϓϨʔεϗϧμ
# Good
Post.where("title = ?", title)
w จࣈྻ݁߹ʢల։ʣͳͲͰΫΤϦΛΈཱͯͯͳΒͳ͍
# Bad
Post.where("title = '#{title}'")
Post.find_by_sql("SELECT * FROM posts WHERE title = '#{title}'")
w "DUJWF3FDPSEͰҾΛαχλΠζ͠ͳ͍ϝιου͕͋ΔͷͰɺ
ҙͯ͠42-Λॻ͘
w IUUQTSBJMTTRMJPSH
Slide 63
Slide 63 text
ͦͷଞͷ੬ऑੑ
w ڧ੍ϒϥζ
w 63-ʹΞΫηε͢Δ͜ͱͰඇެ։ϙετΛݟΕΔ
w JEʹΑΔ࿈൪ QPTUTͷΑ͏ͳ
ͳͷͰɺਪଌ͕༰қ
w ྫ͑ɺҙͷϑΝΠϧڞ༗Λߦ͏߹ͳͲʮڞ༗ͨ͠Ϣʔβʔ͔֬ೝ͢Δʯʮे
ʹෳࡶͰ͍JEʢQPTUT,X%XC#QHO"K"-"%ͷΑ͏ͳ
Λൃߦ͢ΔʯͳͲ͢Δ
w ੬ऑੑͱ͍͏ΑΓվળͨ͠ํ͕ྑ͍
w $PPLJFʹ)UUQ0OMZଐੑ
TFDVSFଐੑ͕༩͞Ε͍ͯͳ͍
w )551ͰͷϩάΠϯ͕Մೳ
w ΞΧϯτϩοΫͳ͠
w ੬ऑͳύεϫʔυʢQBTTXPSEʣ͕༻Մೳ
Slide 64
Slide 64 text
ͦͷଞͷΑ͘ݟΔ੬ऑੑ
Slide 65
Slide 65 text
ΦʔϓϯϦμΠϨΫτ
w ࢦఆ͞ΕͨϖʔδϦμΠϨΫτ͢Δࡍʹɺ߈ܸऀ͕ࢦఆͨ͠ҙͷ63-ϦμΠ
ϨΫτ
˖ IUUQTFYNBQMFDPNMPHJO SFEJSFDUIUUQFWJMDPN
w ͦͷυϝΠϯΛ৴པͯ͠ΞΫηεͨ͠ʹؔΘΒͣɺѱҙ͋ΔαΠτʹϦμΠϨ
Ϋτ͞ΕΔͷͰ৴པΛଛͳ͏
w ϦμΠϨΫτઌʹِͷϑΥʔϜΛදࣔͤ͞ΔͳͲͯ͠ϑΟογϯά
w ϦμΠϨΫτઌΛϢʔβʔͷೖྗ͔ΒߦΘͳ͍ɻϗϫΠτϦετԽ͢Δɻ
w IUUQTXXXPXBTQPSHJOEFYQIQ
6OWBMJEBUFE@3FEJSFDUT@BOE@'PSXBSET@$IFBU@4IFFU
w IUUQHJIZPKQEFWTFSJBMKBWBTDSJQUTFDVSJUZ
Slide 66
Slide 66 text
ύεϫʔυ࿙Ӯରࡦ
˖ ػأٙ٦سכ窫㼎ח䎂俑ד⥂㶷׃זְ农〾⻉تً
˖ إزعحءُأزٖحثؚٝ
w ύεϫʔυϦϚΠϯμͰͳ͘ɺύεϫʔυϦηοτͰ
w 0"VUIͳͲͰࣗલͰύεϫʔυΛ࣋ͨͳ͍ํ
w ࠷ۙͷϑϨʔϜϫʔΫͰ҆શੑͷߴ͍ΞϧΰϦζϜ͕࠾༻͞Ε͍ͯΔ
w 3BJMTˠCDSZQU IBT@TFDVSF@QBTTXPSEΛϞσϧʹՃ͢Δ͚ͩ
w %KBOHPˠ1#,%'
w IUUQXXXBUNBSLJUDPKQBJUBSUJDMFTOFXT@IUNM
w IUUQTXXXPXBTQPSHJOEFYQIQ1BTTXPSE@4UPSBHF@$IFBU@4IFFU
Slide 67
Slide 67 text
.BTT"TTJHONFOU
w 3BJMTͰऔΓ্͛ΒΕΔ͜ͱ͕ଟ͍͕ɺͲͷϑϨʔϜϫʔΫͰى͜Δ
w 3BJMTͰ4USPOH1BSBNFUFSͰݕূΛߦ͏
w )551ϦΫΤετͷΛݕࠪͯ͠ϩδοΫ͢
# Controller
class Users < ApplicationController
def create
# params[:user] = {:name => mrtc0, :passwrod => pass}
@user = User.create params[:user]
end
end
# HTTP Request Body
user[name]=mrtc0&user[password]=pass&user[is_admin]=true
Slide 68
Slide 68 text
ϑΝΠϧΞοϓϩʔυ
w %P4ରࡦ
w ڊେͳϑΝΠϧͷૹ৴Λ͙ͨΊʹϑΝΠϧαΠζͷ্ݶΛઃఆ͢Δ͜ͱ
w ͘͠ඇಉظͰ࣮ߦΛߦ͏
w ϑΝΠϧͷछྨͷ੍ݶ
w ֦ுࢠͰͳ͘ɺ.*.&5ZQFɺϚδοΫφϯόʔͳͲͰϑΝΠϧͷछྨΛผ͢Δ
w ֦ுࢠΛِ͠ѱҙ͋Δ3VCZ1)1εΫϦϓτΛΞοϓϩʔυ͞Εͳ͍Α͏ʹ
w อଘ͢ΔࡍϑΝΠϧ໊ʹϥϯμϜͳΛ
w Ͱ͖ͳ͍߹ڐՄՄೳͳจࣈྻΛϗϫΠτϦετԽ
w QBTTXEͳͲΛࢦఆ͞ΕɺσΟϨΫτϦτϥόʔαϧ͞Εͳ͍Α͏ʹ
Slide 69
Slide 69 text
ϑΝΠϧΞοϓϩʔυ
w ѹॖϑΝΠϧΛΞοϓϩʔυ͠ల։͢Δࡍɺల։લʹϑΝΠϧͷछྨల։࣌
ͷαΠζΛ֬ೝ͢Δ
w γϯϘϦοΫϦϯΫΛͬͨ߈ܸ[JQCPNCͳͲΛ͙
w IUUQTIBDLFSPOFDPNSFQPSUT
w ΞΫηε੍ݶɺݖݶΛదʹઃఆ͢Δ
w Ӿཡݖݶͷͳ͍Ϣʔβʔ͕ӾཡɺμϯϩʔυͰ͖ͳ͍Α͏ʹ
w อଘઌ4ͳͲͷΫϥυετϨʔδαʔϏεΞοϓϩʔυ͢Δ͜ͱΛݕ౼͢
Δ
w อݥతରࡦ͕ͩɺΞϓϦέʔγϣϯͱΓ͢͜ͱͰηΩϡϦςΟΛ؇
Slide 70
Slide 70 text
FWBM
w จࣈྻΛίʔυͱͯ͠ධՁ͢Δؔ
w FWBM BMFSU
w ҙͷίʔυ࣮ߦ͕ՄೳͳͷͰɺҾʹ֎෦͔ΒͷೖྗΛ༩͑
ͳ͍ͳͲͷରࡦΛߦ͏͜ͱ
w FWBMͱ͍͏໊લͰͳͯ͘ಉͷػೳΛ͕࣋ͭؔଘࡏ͢ΔͷͰ
ҙ
eval('alert(1)')
Slide 71
Slide 71 text
ηΩϡϦςΟؔͷ)551ϔομ
w ৭ʑ͋Δ͕ɺͱΓ͚͓͚͋͑ͣͭͯͱ͍͏ϔομ
w 99441SPUFDUJPONPEFCMPDL
w 944'JMUFS"VEJUPSΛ༗ޮ
w 9$POUFOU5ZQF0QUJPOTOPTOJ⒎
w *&$POUFOU5ZQFΛແࢹ͢Δ͜ͱ͕͋ΔͷͰ
w 9'SBNF0QUJPOT4".&03*(*/
w ΫϦοΫδϟοΩϯάࢭ
w વΞϓϦέʔγϣϯʹΑͬͯઃఆ͢ΔมΘΔͷͰɺదʹઃఆ͢Δ͜ͱ
Slide 72
Slide 72 text
-FUT੬ऑੑஅ
w ౡ͝ͱʹνʔϜʹͳͬͯஅΛ͍ͯͩ͘͠͞
w ࠷ޙʹ֤νʔϜʹݟ͚ͭͨ੬ऑੑʹ͍ͭͯൃදͯ͠Β͍·͢
w Ͳͷը໘ 63-
Ͱ
w Ͳ͏͍ͬͨૢ࡞Λͨ͠Β
w Ͳ͏͍ͬͨ੬ऑੑ͕ݟ͔͔ͭͬͨ
w ͜ͷΞϓϦέʔγϣϯͰͲͷΑ͏ͳӨڹ͕͋Δ͔ʢͰ͖Εରࡦʹ͍ͭͯʣ
w ൃදޙ$ZCP[V-JWFʹ֤νʔϜ͕ݟ͚ͭͨ੬ऑੑͷ؆қใࠂॻΛΞοϓ͍ͯͩ͘͠͞ɻ
w ݟ͚ͭͨΒҰਓ͕ใࠂॻ࡞ʹճΔͳͲɺޮతͳஅΛ͢Δ͜ͱΛΦεεϝ͠·
͢ɻ
Slide 73
Slide 73 text
ҙɾېࢭࣄ߲
w ҙࣄ߲
w ొ͢Δύεϫʔυීஈ͍ͬͯͳ͍ͷʹ͍ͯͩ͘͠͞
w ېࢭࣄ߲
w ଞਓͷ߈ܸɺεΩϟϯͳͲෛՙΛ͔͚Δ߈ܸɺσʔλϕʔε
আͳͲͷةݥͳ߈ܸ
w ωοτϫʔΫஅͰͳ͍ͷͰ/NBQͳͲېࢭ
Slide 74
Slide 74 text
੬ऑੑใࠂλΠϜ
w νʔϜͰදऀਓ͕ݟ͚ͭͨ੬ऑੑʹ͍ͭͯͭൃද
w Ͳͷը໘ 63-
Ͱ
w Ͳ͏͍ͬͨૢ࡞Λͨ͠Β
w Ͳ͏͍ͬͨ੬ऑੑ͕ݟ͔͔ͭͬͨ
w ͜ͷΞϓϦέʔγϣϯͰͲͷΑ͏ͳӨڹ͕͋Δ͔ʢͰ͖Ε
ରࡦʹ͍ͭͯʣ
w ൃදޙʹ؆қใࠂॻΛ$ZCP[V-JWFʹڞ༗͍ͯͩ͘͠͞
Slide 75
Slide 75 text
·ͱΊ
w 8FCΞϓϦέʔγϣϯஅͷίπ
w 8FCΤεύʔɻΞϓϦέʔγϣϯͷؾ࣋ͪʹͳΔ
w ༷Λ͍ͪૣ͘௫Ή
w ڍಈΛཧղ͢Δ
w ͲͷΑ͏ͳॲཧ͕ߦΘΕ͍ͯΔͷ͔
w ΞϓϦέʔγϣϯͷཪଆΛ૾͢Δྗ͕ඞཁ
Slide 76
Slide 76 text
·ͱΊ
w ։ൃऀηΩϡϦςΟΛֶͳ͚ΕͳΒͳ͍
w Ͳ͏͍͏࣮ͰͲ͏͍͏੬ऑੑ͕࡞Γࠐ·ΕΔ͔ΛΒͳ͚Ε
ͳΒͳ͍
w ։ൃʹۜͷؙͳ͍
w ϑϨʔϜϫʔΫͰશͯͷ੬ऑੑΛղܾͯ͘͠Εͳ͍
w ։ൃޙʹஅͰͳ͘ɺ։ൃαΠΫϧʹݕࠪΛೖΕΔ
Slide 77
Slide 77 text
ҙࣄ߲ʢ࠶ܝʣ
˖ 盖鱥㢩ך،فٔ؛٦ءّٝח㼎׃ג窫㼎余䷼׃זְ
w #VH#PVOUZ੍
w IBDLFSPOFɿIUUQTXXXIBDLFSPOFDPN
w $ZCP[V੬ऑੑใ੍ۚ
w *1"ʹใࠂ͠Α͏
w IUUQTXXXJQBHPKQTFDVSJUZWVMOSFQPSU
w ࠷Ͱࠓճॻ͍ͨ؆қใࠂॻϨϕϧͷ༰Ͱಧ͚ग़͠Α͏
Slide 78
Slide 78 text
அ͢Δͱ͖
w ͨͱ͑ࣗͷΞϓϦέʔγϣϯͰ͋ͬͯɺΫϥυαʔϏεΛ
ར༻͢Δࡍਃ͕ඞཁͳ߹͕͋Δ
w ಛʹ"84
w IUUQUJHFST[LIBUFOBCMPHDPNFOUSZ
Slide 79
Slide 79 text
ࢀߟ
w ମܥతʹֶͿ҆શͳ8FCΞϓϦέʔγϣϯͷ࡞Γํ
w IUUQTXXXBNB[PODPKQEQ
w ΊΜͲ͏͍͘͞8FCηΩϡϦςΟ
w IUUQTXXXBNB[PODPKQEQ
w ҆શͳΣϒαΠτͷ࡞Γํ
w IUUQTXXXJQBHPKQTFDVSJUZWVMOXFCTFDVSJUZIUNM
w 3BJMT42-*OKFDUJPO
w IUUQTSBJMTTRMJPSH
w 08"41501
w IUUQTXXXPXBTQPSHJOEFYQIQ5PQ@@5PQ@