[{"data":1,"prerenderedAt":1138},["ShallowReactive",2],{"course-mcp-security":3,"lesson-mcp-security-lab":160},{"course":4,"lessons":82},{"id":5,"title":6,"body":7,"code":62,"cover":64,"date":65,"description":66,"draft":67,"duration":68,"extension":69,"level":70,"meta":71,"navigation":72,"ogTitle":73,"path":74,"pin":67,"seo":75,"sitemap":76,"stem":77,"tags":78,"updated":68,"__hash__":81},"courses\u002Fcourses\u002Fmcp-security\u002Findex.md","ทำ MCP Server ให้ปลอดภัยตาม OWASP MCP Top 10",{"type":8,"value":9,"toc":57},"minimark",[10,25,28,31,36],[11,12,13,14,19,20,24],"p",{},"คอร์สนี้ต่อจาก ",[15,16,18],"a",{"href":17},"\u002Fcourses\u002Fmcp-server","สร้าง MCP Server ด้วย Python เพื่อให้ AI Agent ใช้งานแอปของเราได้"," ใครทำคอร์สนั้นจบแล้วจะมีโฟลเดอร์ ",[21,22,23],"code",{},"cafe-mcp"," อยู่ในมือ ซึ่งใช้งานได้ แต่ยังไม่ปลอดภัย HTTP ไม่มี authentication ค่าที่ AI ส่งมาเชื่อไม่ได้ และ server ของคนอื่นที่ติดตั้งเข้ามารันด้วยสิทธิ์ของเรา",[11,26,27],{},"เราจะไล่ตาม OWASP MCP Top 10 บนแอปร้านกาแฟเดิม แต่ละหัวข้อเขียนฝั่งโจมตีให้เห็นผลที่ตามมา แล้วเขียนฝั่งป้องกันและเทสต์ที่ Fail เมื่อ guard หายไป",[11,29,30],{},"ทุกการโจมตีรันบนเครื่องของเราเอง ข้อมูลที่ \"ถูกขโมย\" ลงไฟล์ในโฟลเดอร์เดียวกัน ไม่มี request ออกนอกเครื่อง",[32,33,35],"h2",{"id":34},"prerequisites","Prerequisites",[37,38,39,50],"ul",{},[40,41,42,43,46,47,49],"li",{},"ทำคอร์ส ",[15,44,45],{"href":17},"MCP Server with Python"," จบ และเก็บโฟลเดอร์ ",[21,48,23],{}," ไว้",[40,51,52,53,56],{},"เครื่อง macOS หรือ Linux (บางบทใช้ ",[21,54,55],{},"sandbox-exec"," ของ macOS และบอกทางเลือกไว้ให้)",{"title":58,"searchDepth":59,"depth":59,"links":60},"",2,[61],{"id":34,"depth":59,"text":35},{"repo":63,"path":23},"https:\u002F\u002Fgithub.com\u002Fiamthana\u002Fiamthana-com-course-code","\u002Fimages\u002Fcourses\u002Fmcp-security\u002Fcover.svg","2026-11-24","ลองโจมตีและป้องกัน MCP Server ของร้านกาแฟตามรายการ OWASP MCP Top 10 ตั้งแต่ token และ scope, tool poisoning, HTTP ที่ไม่ตรวจ Host ไปจนถึง command injection, audit log และ server ที่ไม่มีใครรู้ว่าติดตั้งไว้",false,null,"md","intermediate",{},true,"MCP Security","\u002Fcourses\u002Fmcp-security",{"title":6,"description":66},{"loc":74,"lastmod":65},"courses\u002Fmcp-security\u002Findex",[79,80],"AI","Python","Jj0H3S1MTu7O-U-6s8A0fKIybOjLv0NweFswely9yyQ",[83,90,96,103,109,115,122,129,135,141,148,154],{"path":84,"title":85,"description":86,"duration":87,"order":88,"slug":89},"\u002Fcourses\u002Fmcp-security\u002Flab","Set Up the Security Lab","ดูว่า OWASP MCP Top 10 แต่ละข้ออยู่บทไหนของคอร์สนี้ แล้วเตรียมโฟลเดอร์ cafe-mcp จากคอร์สแรกให้พร้อมทดลองโจมตีบนเครื่องตัวเอง ทั้ง Database http_server.py และตัวแปร curl","15 min","1","lab",{"path":91,"title":92,"description":93,"duration":87,"order":94,"slug":95},"\u002Fcourses\u002Fmcp-security\u002Fresource-injection","Untrusted Text in Resources","สร้างออร์เดอร์ที่ลูกค้าตั้งชื่อตัวเองเป็นประโยคคำสั่ง ดูว่าข้อความนั้นไปถึง AI ผ่าน resource ยังไง แล้วลดความเสี่ยงฝั่ง server ด้วยการส่งเท่าที่จำเป็น","2","resource-injection",{"path":97,"title":98,"description":99,"duration":100,"order":101,"slug":102},"\u002Fcourses\u002Fmcp-security\u002Fauth","Require a Token","ให้ HTTP server ของ cafe-mcp รับเฉพาะ request ที่มี token ของตัวเอง ทดสอบด้วย curl แล้วต่อ Claude Code โดยไม่เขียน token ลงไฟล์ config","25 min","3","auth",{"path":104,"title":105,"description":106,"duration":100,"order":107,"slug":108},"\u002Fcourses\u002Fmcp-security\u002Fscopes","Limit Tools by Scope","ให้ tool ที่แก้ข้อมูลเช็ก scope orders:write ก่อนทำงาน viewer ยกเลิกออร์เดอร์ไม่ได้และไม่เห็นคำถามยืนยันด้วย ทดสอบด้วย curl, pytest และ Claude Code","4","scopes",{"path":110,"title":111,"description":112,"duration":100,"order":113,"slug":114},"\u002Fcourses\u002Fmcp-security\u002Ftool-attacks","Run Tool Attacks","เขียน server โจมตี 2 ตัวรันบนเครื่องตัวเอง promo_server.py ซ่อนคำสั่งใน description (tool poisoning) และแอบอ่าน cafe.db โดยไม่ผ่าน token ส่วน promo_rugpull_server.py เปลี่ยน description หลังอนุมัติ (rug pull) แล้วลองกับ Claude Code ข้อมูลที่ขโมยได้ลงแค่ไฟล์ stolen.log","5","tool-attacks",{"path":116,"title":117,"description":118,"duration":119,"order":120,"slug":121},"\u002Fcourses\u002Fmcp-security\u002Ftool-defenses","Defend Against Tool Attacks","ปิดช่องของบท Run Tool Attacks ทีละจุด เขียน review_tools.py ที่พิมพ์ description เต็มพร้อมคำเตือน เก็บ hash ใน tools.lock.json ไว้จับ rug pull แล้วรัน server แบบ stdio ใน sandbox ที่อ่าน cafe.db ไม่ได้ จากนั้นรันการโจมตีเดิมซ้ำ","30 min","6","tool-defenses",{"path":123,"title":124,"description":125,"duration":126,"order":127,"slug":128},"\u002Fcourses\u002Fmcp-security\u002Fhttp-attacks","HTTP Attacks","ส่ง Host และ Origin แปลก ๆ เข้า http_server.py กับ open_server.py ที่ไม่ตรวจอะไรเลย เทียบค่าเริ่มต้นของ SDK เมื่อ bind ที่ 127.0.0.1 กับ 0.0.0.0 และดูโค้ด token passthrough ที่ spec ห้าม","20 min","7","http-attacks",{"path":130,"title":131,"description":132,"duration":119,"order":133,"slug":134},"\u002Fcourses\u002Fmcp-security\u002Fhttp-defenses","Defend the HTTP Server","ตั้ง transport_security ของ http_server.py ให้รับแค่ Host 127.0.0.1:8765 ที่ไม่มี Origin เรียก API ปลายทางด้วย credential ของ server เอง เขียน pytest แล้วทำให้ Fail เพื่อพิสูจน์ว่าจับได้ ปิดท้ายด้วย checklist ก่อนติดตั้งและก่อนเปิด server","8","http-defenses",{"path":136,"title":137,"description":138,"duration":100,"order":139,"slug":140},"\u002Fcourses\u002Fmcp-security\u002Fcommand-injection","Shell Commands from Tool Input","เขียน print_receipt ที่ต่อคำสั่ง shell จากชื่อลูกค้ากับชื่อไฟล์ ใส่ชื่อลูกค้าที่มีคำสั่ง touch แทรกอยู่แล้วดู shell รันตาม จากนั้นเปลี่ยนเป็น subprocess แบบ list กับ allowlist ของชื่อไฟล์ พร้อม pytest ที่ Fail เมื่อถอดการป้องกันออก","9","command-injection",{"path":142,"title":143,"description":144,"duration":145,"order":146,"slug":147},"\u002Fcourses\u002Fmcp-security\u002Faudit-log","Audit Tool Calls","เพิ่ม audit log แบบ JSON lines ให้ HTTP server ของ cafe-mcp บันทึกว่าใครเรียก tool ไหนด้วย argument อะไรและผลเป็นอย่างไร โดยซ่อนชื่อลูกค้าและไม่เก็บ token แล้วใช้ jq หาว่าใครยกเลิกออร์เดอร์","35 min","10","audit-log",{"path":149,"title":150,"description":151,"duration":100,"order":152,"slug":153},"\u002Fcourses\u002Fmcp-security\u002Fsupply-chain","Lock Dependencies and Pin Servers","ล็อก dependency ของ cafe-mcp ด้วย uv.lock แล้วแก้ pyproject.toml กับ hash ใน lock ให้ uv sync --locked Fail ใส่เลขเวอร์ชันในคำสั่ง npx กับ uvx ใช้ review_tools.py check จับ server ที่เปลี่ยนหลังอัปเกรด และตรวจ dependency ด้วย pip-audit","11","supply-chain",{"path":155,"title":156,"description":157,"duration":119,"order":158,"slug":159},"\u002Fcourses\u002Fmcp-security\u002Fshadow-servers","Find Shadow Servers","เขียน inventory.py ค้นหา .mcp.json ในทุกโฟลเดอร์ย่อยแล้วบอกว่าคำสั่ง npx กับ uvx ตัวไหนไม่ได้ล็อกเวอร์ชัน ใช้ lsof กับ curl หา server ที่เปิด port ค้างอยู่บนเครื่อง และดู policy ของ Claude Code ที่คุม server ทั้งองค์กร","12","shadow-servers",{"id":161,"title":85,"body":162,"codeTag":1131,"description":86,"draft":67,"duration":87,"extension":69,"meta":1132,"navigation":72,"ogTitle":1133,"order":88,"path":84,"seo":1134,"sitemap":1135,"stem":1136,"updated":68,"__hash__":1137},"lessons\u002Fcourses\u002Fmcp-security\u002F01.lab.md",{"type":8,"value":163,"toc":1117},[164,170,174,177,354,358,361,425,432,449,453,462,605,618,622,632,653,658,664,699,704,708,715,791,794,810,819,823,832,858,867,871,878,1021,1028,1031,1048,1055,1058,1062,1072,1080,1084,1093,1097,1113],[11,165,166,167,169],{},"คอร์สนี้เราจะลองโจมตี ",[21,168,23],{}," ของตัวเองตามรายการ OWASP MCP Top 10 แล้วปิดช่องทีละข้อครับ บทนี้ดูรายการนั้นก่อน แล้วเตรียมเครื่องให้พร้อม",[32,171,173],{"id":172},"what-is-owasp-mcp-top-10","What Is OWASP MCP Top 10",[11,175,176],{},"OWASP คือองค์กรที่ทำรายการช่องโหว่ที่เจอบ่อย อย่าง OWASP Top 10 ของเว็บ ส่วนของ MCP มี 10 ข้อตามตารางนี้ (ฉบับ 2025 สถานะ beta) คอลัมน์ขวาบอกว่าคอร์สนี้ลองข้อนั้นในบทไหน",[178,179,180,196],"table",{},[181,182,183],"thead",{},[184,185,186,190,193],"tr",{},[187,188,189],"th",{},"ID",[187,191,192],{},"Item",[187,194,195],{},"Covered In",[197,198,199,222,234,249,270,282,294,313,325,337],"tbody",{},[184,200,201,205,208],{},[202,203,204],"td",{},"MCP01",[202,206,207],{},"Token Mismanagement & Secret Exposure",[202,209,210,212,213,215,216,218,219,221],{},[15,211,98],{"href":97}," (token อยู่ใน environment variable), ",[15,214,124],{"href":123}," กับ ",[15,217,131],{"href":130}," (token passthrough) และ ",[15,220,143],{"href":142}," (token ไม่เข้า log)",[184,223,224,227,230],{},[202,225,226],{},"MCP02",[202,228,229],{},"Privilege Escalation via Scope Creep",[202,231,232],{},[15,233,105],{"href":104},[184,235,236,239,242],{},[202,237,238],{},"MCP03",[202,240,241],{},"Tool Poisoning",[202,243,244,246,247],{},[15,245,111],{"href":110}," และ ",[15,248,117],{"href":116},[184,250,251,254,257],{},[202,252,253],{},"MCP04",[202,255,256],{},"Software Supply Chain Attacks & Dependency Tampering",[202,258,259,215,261,263,264,266,267,269],{},[15,260,111],{"href":110},[15,262,117],{"href":116}," (server ที่เปลี่ยนหลังติดตั้ง), ",[15,265,150],{"href":149}," (lock, hash และเวอร์ชันของคำสั่ง) และ ",[15,268,156],{"href":155}," (หาคำสั่งที่ไม่ได้ล็อกเวอร์ชัน)",[184,271,272,275,278],{},[202,273,274],{},"MCP05",[202,276,277],{},"Command Injection & Execution",[202,279,280],{},[15,281,137],{"href":136},[184,283,284,287,290],{},[202,285,286],{},"MCP06",[202,288,289],{},"Prompt Injection via Contextual Payloads",[202,291,292],{},[15,293,92],{"href":91},[184,295,296,299,302],{},[202,297,298],{},"MCP07",[202,300,301],{},"Insufficient Authentication & Authorization",[202,303,304,306,307,306,309,246,311],{},[15,305,98],{"href":97},", ",[15,308,105],{"href":104},[15,310,124],{"href":123},[15,312,131],{"href":130},[184,314,315,318,321],{},[202,316,317],{},"MCP08",[202,319,320],{},"Lack of Audit and Telemetry",[202,322,323],{},[15,324,143],{"href":142},[184,326,327,330,333],{},[202,328,329],{},"MCP09",[202,331,332],{},"Shadow MCP Servers",[202,334,335],{},[15,336,156],{"href":155},[184,338,339,342,345],{},[202,340,341],{},"MCP10",[202,343,344],{},"Context Injection & Over-Sharing",[202,346,347,349,350,353],{},[15,348,92],{"href":91}," (",[21,351,352],{},"sales_resource"," ไม่ส่งชื่อลูกค้า)",[32,355,357],{"id":356},"trust-boundary","Trust Boundary",[11,359,360],{},"เวลา AI หรือ server ได้รับข้อความ คอร์สนี้จะดูก่อนเสมอครับว่าใครเป็นคนเขียน เส้นแบ่งระหว่างข้อความที่เราเขียนเองกับข้อความที่คนอื่นเขียนเรียกว่า trust boundary",[178,362,363,376],{},[181,364,365],{},[184,366,367,370,373],{},[187,368,369],{},"Text",[187,371,372],{},"Written By",[187,374,375],{},"Reaches",[197,377,378,392,403,414],{},[184,379,380,386,389],{},[202,381,382,385],{},[21,383,384],{},"description"," ของ tool",[202,387,388],{},"developer ของ server (เราเอง หรือคนอื่นถ้าเป็น server ที่ติดตั้งมา)",[202,390,391],{},"AI อ่านก่อนเลือกเรียก tool",[184,393,394,397,400],{},[202,395,396],{},"argument ของ tool",[202,398,399],{},"AI เลือกเองจากข้อความที่อ่านมา",[202,401,402],{},"server ที่รับ request",[184,404,405,408,411],{},[202,406,407],{},"ข้อความใน resource (ชื่อลูกค้า โน้ต)",[202,409,410],{},"ลูกค้าหรือใครก็ตามที่พิมพ์ลง Database ได้",[202,412,413],{},"AI ผ่าน host",[184,415,416,419,422],{},[202,417,418],{},"token ใน header",[202,420,421],{},"client ที่ต่อเข้ามา",[202,423,424],{},"server",[11,426,427,428,431],{},"ในตารางนี้มีแค่ description ของ ",[21,429,430],{},"cafe"," ที่เราเขียนเอง ที่เหลือเราไม่ได้เขียนเอง เลยเชื่อไม่ได้จนกว่าจะตรวจ แต่ละแบบตรวจคนละที่",[37,433,434,437,440,443],{},[40,435,436],{},"description ของ server ที่ติดตั้งมา เราอ่านเองก่อนอนุมัติ แล้วเช็กซ้ำว่ามันไม่เปลี่ยนทีหลัง",[40,438,439],{},"argument ของ tool ให้ server ตรวจก่อนเอาไปใช้",[40,441,442],{},"ข้อความใน resource server บอกไม่ได้ว่า AI จะทำตามคำสั่งที่แฝงมาไหม ทำได้แค่ตรวจรูปแบบตอนเขียนลง Database ส่งเท่าที่จำเป็น และให้คนยืนยันก่อน tool แก้ข้อมูล",[40,444,445,446,448],{},"token ให้ server ตรวจว่าออกมาให้ ",[21,447,430],{}," จริง และมี scope (สิทธิ์ที่ติดมากับ token) พอสำหรับ tool ที่เรียก",[32,450,452],{"id":451},"what-you-need","What You Need",[11,454,455,456,458,459,461],{},"คอร์สนี้ต่อจากคอร์ส ",[15,457,45],{"href":17}," โฟลเดอร์ ",[21,460,23],{}," ที่ได้จากคอร์สนั้นต้องมีของตามตารางนี้ ถ้าขาดอันไหนให้กลับไปทำบทในคอลัมน์ขวา",[178,463,464,474],{},[181,465,466],{},[184,467,468,471],{},[187,469,470],{},"Needed",[187,472,473],{},"Lesson",[197,475,476,494,507,536,547,561,575,591],{},[184,477,478,488],{},[202,479,480,483,484,487],{},[21,481,482],{},"database.py"," ที่สร้าง ",[21,485,486],{},"cafe.db"," พร้อมข้อมูลตั้งต้น",[202,489,490],{},[15,491,493],{"href":492},"\u002Fcourses\u002Fmcp-server\u002Ffirst-tool","Build Your First Tool",[184,495,496,501],{},[202,497,498],{},[21,499,500],{},"http_server.py",[202,502,503],{},[15,504,506],{"href":505},"\u002Fcourses\u002Fmcp-server\u002Finspect-traffic","Intercept Requests and Responses",[184,508,509,530],{},[202,510,511,514,515,306,518,306,521,306,524,246,527],{},[21,512,513],{},"cafe_server.py"," ที่มี ",[21,516,517],{},"list_menu",[21,519,520],{},"create_order",[21,522,523],{},"cancel_order",[21,525,526],{},"ask_cancel_confirmation",[21,528,529],{},"load_order",[202,531,532],{},[15,533,535],{"href":534},"\u002Fcourses\u002Fmcp-server\u002Forders","Confirm Actions with Elicitation",[184,537,538,541],{},[202,539,540],{},"resource ของเมนู ออร์เดอร์ ยอดขาย และสูตร",[202,542,543],{},[15,544,546],{"href":545},"\u002Fcourses\u002Fmcp-server\u002Fresources","Expose Data with Resources",[184,548,549,555],{},[202,550,551,552],{},"prompt ",[21,553,554],{},"daily_summary",[202,556,557],{},[15,558,560],{"href":559},"\u002Fcourses\u002Fmcp-server\u002Fprompts","Build a Prompt",[184,562,563,569],{},[202,564,565,566],{},"completion ของชื่อเมนูกับ ",[21,567,568],{},"size",[202,570,571],{},[15,572,574],{"href":573},"\u002Fcourses\u002Fmcp-server\u002Fcompletion","Autocomplete with Completion",[184,576,577,585],{},[202,578,579,215,582],{},[21,580,581],{},"stock_server.py",[21,583,584],{},"notify_server.py",[202,586,587],{},[15,588,590],{"href":589},"\u002Fcourses\u002Fmcp-server\u002Fstock-notify","Add Stock and Notify Servers",[184,592,593,599],{},[202,594,595,598],{},[21,596,597],{},"tests\u002F"," ที่ผ่านทั้ง 14 ตัว",[202,600,601],{},[15,602,604],{"href":603},"\u002Fcourses\u002Fmcp-server\u002Ftesting","Test with pytest",[11,606,607,608,215,614,617],{},"ต้องใช้ ",[15,609,613],{"href":610,"rel":611},"https:\u002F\u002Fcode.claude.com\u002Fdocs",[612],"nofollow","Claude Code",[21,615,616],{},"curl"," เหมือนคอร์สแรก",[32,619,621],{"id":620},"set-up","Set Up",[11,623,624,625,627,628,631],{},"ทุกคำสั่งของคอร์สนี้รันในโฟลเดอร์ ",[21,626,23],{}," เปิด terminal แล้วเข้าไปที่โฟลเดอร์นั้นก่อน (เปลี่ยน ",[21,629,630],{},"\u002Fpath\u002Fto\u002Fcafe-mcp"," เป็น path จริงบนเครื่อง)",[633,634,638],"pre",{"className":635,"code":636,"language":637,"meta":58,"style":58},"language-bash shiki shiki-themes one-dark-pro one-dark-pro github-dark","cd \u002Fpath\u002Fto\u002Fcafe-mcp\n","bash",[21,639,640],{"__ignoreMap":58},[641,642,645,649],"span",{"class":643,"line":644},"line",1,[641,646,648],{"class":647},"syY4w","cd",[641,650,652],{"class":651},"sxpJ6"," \u002Fpath\u002Fto\u002Fcafe-mcp\n",[654,655,657],"h3",{"id":656},"database","Database",[11,659,660,661,663],{},"เลขออร์เดอร์ในตัวอย่างของคอร์สนี้นับต่อจากข้อมูลตั้งต้น เลยต้องลบ ",[21,662,486],{}," แล้วสร้างใหม่ ออร์เดอร์ที่สร้างไว้ตอนเรียนคอร์สแรกจะหายไป",[633,665,667],{"className":635,"code":666,"language":637,"meta":58,"style":58},"rm -f cafe.db\nuv run python -c \"from database import connect; connect().close()\"\n",[21,668,669,682],{"__ignoreMap":58},[641,670,671,675,679],{"class":643,"line":644},[641,672,674],{"class":673},"sPHSi","rm",[641,676,678],{"class":677},"sKibB"," -f",[641,680,681],{"class":651}," cafe.db\n",[641,683,684,687,690,693,696],{"class":643,"line":59},[641,685,686],{"class":673},"uv",[641,688,689],{"class":651}," run",[641,691,692],{"class":651}," python",[641,694,695],{"class":677}," -c",[641,697,698],{"class":651}," \"from database import connect; connect().close()\"\n",[11,700,701,703],{},[21,702,486],{}," ใหม่มีออร์เดอร์ 1 กับ 2",[654,705,707],{"id":706},"http-server","HTTP Server",[11,709,710,712,713],{},[21,711,500],{}," จากคอร์สแรกมีแค่นี้ คอร์สนี้จะแก้ไฟล์นี้ในบท ",[15,714,131],{"href":130},[633,716,721],{"className":717,"code":718,"filename":500,"language":719,"meta":720,"style":58},"language-python shiki shiki-themes one-dark-pro one-dark-pro github-dark","from cafe_server import mcp\n\nmcp.run(transport=\"streamable-http\", host=\"127.0.0.1\", port=8765)\n","python","tangle=expect",[21,722,723,739,744],{"__ignoreMap":58},[641,724,725,729,733,736],{"class":643,"line":644},[641,726,728],{"class":727},"s0bQv","from",[641,730,732],{"class":731},"s3ef5"," cafe_server ",[641,734,735],{"class":727},"import",[641,737,738],{"class":731}," mcp\n",[641,740,741],{"class":643,"line":59},[641,742,743],{"emptyLinePlaceholder":72},"\n",[641,745,747,750,754,757,761,765,768,770,773,775,778,780,783,785,788],{"class":643,"line":746},3,[641,748,749],{"class":731},"mcp.",[641,751,753],{"class":752},"s9GeD","run",[641,755,756],{"class":731},"(",[641,758,760],{"class":759},"sBAOq","transport",[641,762,764],{"class":763},"sUool","=",[641,766,767],{"class":651},"\"streamable-http\"",[641,769,306],{"class":731},[641,771,772],{"class":759},"host",[641,774,764],{"class":763},[641,776,777],{"class":651},"\"127.0.0.1\"",[641,779,306],{"class":731},[641,781,782],{"class":759},"port",[641,784,764],{"class":763},[641,786,787],{"class":677},"8765",[641,789,790],{"class":731},")\n",[11,792,793],{},"รันค้างไว้ในหน้าต่างนี้",[633,795,797],{"className":635,"code":796,"language":637,"meta":58,"style":58},"uv run python http_server.py\n",[21,798,799],{"__ignoreMap":58},[641,800,801,803,805,807],{"class":643,"line":644},[641,802,686],{"class":673},[641,804,689],{"class":651},[641,806,692],{"class":651},[641,808,809],{"class":651}," http_server.py\n",[633,811,817],{"className":812,"code":814,"filename":815,"language":816,"meta":58},[813],"language-text","INFO:     Uvicorn running on http:\u002F\u002F127.0.0.1:8765 (Press CTRL+C to quit)\n","$ uv run python http_server.py","text",[21,818,814],{"__ignoreMap":58},[654,820,822],{"id":821},"curl-variables","curl Variables",[11,824,825,826,828,829,831],{},"เปิด terminal อีกหน้าต่างสำหรับ curl แล้ว ",[21,827,648],{}," เข้า ",[21,830,23],{}," เหมือนเดิม จากนั้นตั้งตัวแปรสองตัวนี้",[633,833,835],{"className":635,"code":834,"language":637,"meta":58,"style":58},"URL=http:\u002F\u002F127.0.0.1:8765\u002Fmcp\nMETA='\"_meta\":{\"io.modelcontextprotocol\u002FprotocolVersion\":\"2026-07-28\",\"io.modelcontextprotocol\u002FclientCapabilities\":{}}'\n",[21,836,837,848],{"__ignoreMap":58},[641,838,839,843,845],{"class":643,"line":644},[641,840,842],{"class":841},"sDqL8","URL",[641,844,764],{"class":763},[641,846,847],{"class":651},"http:\u002F\u002F127.0.0.1:8765\u002Fmcp\n",[641,849,850,853,855],{"class":643,"line":59},[641,851,852],{"class":841},"META",[641,854,764],{"class":763},[641,856,857],{"class":651},"'\"_meta\":{\"io.modelcontextprotocol\u002FprotocolVersion\":\"2026-07-28\",\"io.modelcontextprotocol\u002FclientCapabilities\":{}}'\n",[11,859,860,862,863,866],{},[21,861,852],{}," คือ ",[21,864,865],{},"_meta"," ที่ทุก request ต้องแนบ ตัวแปรอยู่แค่ในหน้าต่างที่ตั้ง ถ้าเปิดหน้าต่างใหม่ต้องตั้งอีกรอบ",[32,868,870],{"id":869},"check-the-lab","Check the Lab",[11,872,873,874,215,876],{},"เช็กสองอย่างในหน้าต่าง curl ครับ อย่างแรกคือ server ตอบ request ที่ใช้ ",[21,875,842],{},[21,877,852],{},[633,879,881],{"className":635,"code":880,"language":637,"meta":58,"style":58},"curl -s -o \u002Fdev\u002Fnull -w '%{http_code}\\n' $URL \\\n  -H 'Content-Type: application\u002Fjson' \\\n  -H 'Accept: application\u002Fjson, text\u002Fevent-stream' \\\n  -H 'MCP-Protocol-Version: 2026-07-28' \\\n  -H 'Mcp-Method: tools\u002Flist' \\\n  -d \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"id\\\":1,\\\"method\\\":\\\"tools\u002Flist\\\",\\\"params\\\":{$META}}\"\n",[21,882,883,908,918,927,937,947],{"__ignoreMap":58},[641,884,885,887,890,893,896,899,902,905],{"class":643,"line":644},[641,886,616],{"class":673},[641,888,889],{"class":677}," -s",[641,891,892],{"class":677}," -o",[641,894,895],{"class":651}," \u002Fdev\u002Fnull",[641,897,898],{"class":677}," -w",[641,900,901],{"class":651}," '%{http_code}\\n'",[641,903,904],{"class":841}," $URL",[641,906,907],{"class":647}," \\\n",[641,909,910,913,916],{"class":643,"line":59},[641,911,912],{"class":677},"  -H",[641,914,915],{"class":651}," 'Content-Type: application\u002Fjson'",[641,917,907],{"class":647},[641,919,920,922,925],{"class":643,"line":746},[641,921,912],{"class":677},[641,923,924],{"class":651}," 'Accept: application\u002Fjson, text\u002Fevent-stream'",[641,926,907],{"class":647},[641,928,930,932,935],{"class":643,"line":929},4,[641,931,912],{"class":677},[641,933,934],{"class":651}," 'MCP-Protocol-Version: 2026-07-28'",[641,936,907],{"class":647},[641,938,940,942,945],{"class":643,"line":939},5,[641,941,912],{"class":677},[641,943,944],{"class":651}," 'Mcp-Method: tools\u002Flist'",[641,946,907],{"class":647},[641,948,950,953,956,959,962,964,967,969,972,974,977,979,982,984,987,989,992,994,996,998,1001,1003,1005,1007,1010,1012,1015,1018],{"class":643,"line":949},6,[641,951,952],{"class":677},"  -d",[641,954,955],{"class":651}," \"{",[641,957,958],{"class":647},"\\\"",[641,960,961],{"class":651},"jsonrpc",[641,963,958],{"class":647},[641,965,966],{"class":651},":",[641,968,958],{"class":647},[641,970,971],{"class":651},"2.0",[641,973,958],{"class":647},[641,975,976],{"class":651},",",[641,978,958],{"class":647},[641,980,981],{"class":651},"id",[641,983,958],{"class":647},[641,985,986],{"class":651},":1,",[641,988,958],{"class":647},[641,990,991],{"class":651},"method",[641,993,958],{"class":647},[641,995,966],{"class":651},[641,997,958],{"class":647},[641,999,1000],{"class":651},"tools\u002Flist",[641,1002,958],{"class":647},[641,1004,976],{"class":651},[641,1006,958],{"class":647},[641,1008,1009],{"class":651},"params",[641,1011,958],{"class":647},[641,1013,1014],{"class":651},":{",[641,1016,1017],{"class":841},"$META",[641,1019,1020],{"class":651},"}}\"\n",[633,1022,1026],{"className":1023,"code":1024,"filename":1025,"language":816,"meta":58},[813],"200\n","$ curl ... tools\u002Flist",[21,1027,1024],{"__ignoreMap":58},[11,1029,1030],{},"อย่างที่สองคือเทสต์ของคอร์สแรก",[633,1032,1034],{"className":635,"code":1033,"language":637,"meta":58,"style":58},"uv run pytest -q\n",[21,1035,1036],{"__ignoreMap":58},[641,1037,1038,1040,1042,1045],{"class":643,"line":644},[641,1039,686],{"class":673},[641,1041,689],{"class":651},[641,1043,1044],{"class":651}," pytest",[641,1046,1047],{"class":677}," -q\n",[633,1049,1053],{"className":1050,"code":1051,"filename":1052,"language":816,"meta":58},[813],"..............                                                           [100%]\n14 passed in 0.11s\n","$ uv run pytest -q",[21,1054,1051],{"__ignoreMap":58},[11,1056,1057],{},"ต้องผ่านทั้ง 14 ตัวก่อนเริ่ม เพราะบทต่อ ๆ ไปจะเพิ่มเทสต์เข้าชุดนี้ ถ้าของเดิม Fail อยู่จะแยกไม่ออกว่าพังเพราะโค้ดของบทไหน ถ้าอันไหน Fail ให้กลับไปแก้ที่บทของมันในคอร์สแรก",[32,1059,1061],{"id":1060},"attack-files","Attack Files",[11,1063,1064,1065,306,1068,1071],{},"ไฟล์โจมตีในคอร์สนี้ (",[21,1066,1067],{},"promo_server.py",[21,1069,1070],{},"open_server.py"," และอื่น ๆ) เขียนมาเพื่อทดลอง ข้อมูลที่ \"ถูกขโมย\" ไปลงไฟล์ในโฟลเดอร์เดียวกัน ตัวไฟล์โจมตีไม่ส่งอะไรออกนอกเครื่อง (แต่ตอนลองผ่าน Claude Code ข้อความในบทสนทนาจะถูกส่งไปที่โมเดลตามปกตินะ)",[37,1073,1074,1077],{},[40,1075,1076],{},"รันบนเครื่องของเราเองเท่านั้น ห้ามชี้ไปที่ server หรือเครื่องของคนอื่น",[40,1078,1079],{},"ห้ามคัดโค้ดฝั่งโจมตีไปใช้นอกการทดลอง",[32,1081,1083],{"id":1082},"summary","Summary",[11,1085,1086,1087,1089,1090,1092],{},"บทถัดไป ",[15,1088,92],{"href":91}," เริ่มจากช่องที่ง่ายที่สุด คือข้อความที่ลูกค้าพิมพ์เข้ามาเอง ให้รัน ",[21,1091,500],{}," ค้างไว้ และใช้หน้าต่าง curl เดิมต่อได้เลย",[32,1094,1096],{"id":1095},"references","References",[37,1098,1099,1106],{},[40,1100,1101],{},[15,1102,1105],{"href":1103,"rel":1104},"https:\u002F\u002Fowasp.org\u002Fprojects\u002Fmcp-top-10",[612],"OWASP MCP Top 10",[40,1107,1108],{},[15,1109,1112],{"href":1110,"rel":1111},"https:\u002F\u002Fmodelcontextprotocol.io\u002Fdocs\u002F2026-07-28\u002Ftutorials\u002Fsecurity\u002Fsecurity_best_practices",[612],"Security Best Practices",[1114,1115,1116],"style",{},"html pre.shiki code .syY4w, html code.shiki .syY4w{--shiki-light:#56B6C2;--shiki-default:#56B6C2;--shiki-dark:#79B8FF}html pre.shiki code .sxpJ6, html code.shiki .sxpJ6{--shiki-light:#98C379;--shiki-default:#98C379;--shiki-dark:#9ECBFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sPHSi, html code.shiki .sPHSi{--shiki-light:#61AFEF;--shiki-default:#61AFEF;--shiki-dark:#B392F0}html pre.shiki code .sKibB, html code.shiki .sKibB{--shiki-light:#D19A66;--shiki-default:#D19A66;--shiki-dark:#79B8FF}html pre.shiki code .s0bQv, html code.shiki .s0bQv{--shiki-light:#C678DD;--shiki-default:#C678DD;--shiki-dark:#F97583}html pre.shiki code .s3ef5, html code.shiki .s3ef5{--shiki-light:#ABB2BF;--shiki-default:#ABB2BF;--shiki-dark:#E1E4E8}html pre.shiki code .s9GeD, html code.shiki .s9GeD{--shiki-light:#61AFEF;--shiki-default:#61AFEF;--shiki-dark:#E1E4E8}html pre.shiki code .sBAOq, html code.shiki .sBAOq{--shiki-light:#E06C75;--shiki-light-font-style:italic;--shiki-default:#E06C75;--shiki-default-font-style:italic;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html pre.shiki code .sUool, html code.shiki .sUool{--shiki-light:#56B6C2;--shiki-default:#56B6C2;--shiki-dark:#F97583}html pre.shiki code .sDqL8, html code.shiki .sDqL8{--shiki-light:#E06C75;--shiki-default:#E06C75;--shiki-dark:#E1E4E8}",{"title":58,"searchDepth":59,"depth":59,"links":1118},[1119,1120,1121,1122,1127,1128,1129,1130],{"id":172,"depth":59,"text":173},{"id":356,"depth":59,"text":357},{"id":451,"depth":59,"text":452},{"id":620,"depth":59,"text":621,"children":1123},[1124,1125,1126],{"id":656,"depth":746,"text":657},{"id":706,"depth":746,"text":707},{"id":821,"depth":746,"text":822},{"id":869,"depth":59,"text":870},{"id":1060,"depth":59,"text":1061},{"id":1082,"depth":59,"text":1083},{"id":1095,"depth":59,"text":1096},"mcp-server\u002F11-testing",{},"MCP Security Lab",{"title":85,"description":86},{"loc":84},"courses\u002Fmcp-security\u002F01.lab","rSJYpD9T54lyoW3xVGXvrKwy3tcchmKqWoSMp9-LoZA",1795576463721]