การเขียนโปรแกรม back-end
แนะนำใหม่| English | ความหมาย |
|---|---|
| route/ruːt/ | ทางเชื่อม |
| validate input/ˈvælɪdeɪt ˈɪnpʊt/ | ตรวจสอบข้อมูลเข้า |
| status/ˈsteɪtəs/ | รหัสสถานะ |
| SQL injection/ˌes kjuː ˈel ɪnˈdʒekʃn/ | SQL injection (การแทรกคำสั่ง SQL) |
| parameterised query/ˌpærəˈmetəraɪzd ˈkwɪərɪ/ | คำถามแบบพารามิเตอร์ |
A search string changes the query
- A name search receives
' OR 1=1 --. If code pastes it into SQL, the text may change the condition instead of remaining a name. - A route 路由 maps a request method and path to its handler. Keep the route contract clear before implementing the lookup.
Check shape and permission
- Validate input 校验输入 means checking required values, types, permitted lengths and ranges. Check the caller’s permission separately.
- A status 状态码 describes the result: 200 for this successful lookup, 400 for invalid input and 404 for a missing resource. Permission failures need the application’s agreed policy; they are not automatically bad input.
จับคู่ผลลัพธ์เหล่านี้ภายใต้สัญญาเส้นทางของบทเรียน
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ความหมายเหล่านี้ไม่ได้กำหนดเองว่าความล้มเหลวในการอนุญาตที่เป็นส่วนตัวควรแสดงอย่างไร
Keep values outside the SQL text
- SQL injection SQL 注入 happens when untrusted text becomes part of SQL syntax. A parameterised query 参数化查询 binds a value separately from the statement.
- Placeholders bind values, not arbitrary table names or sort directions. Choose such identifiers from a fixed server-side allowlist when a route needs them.

การค้นหาค่าแบบใดที่ช่วยแยกชื่อที่ถูกส่งมาจากไวยากรณ์ SQL?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
การผูกค่าช่วยให้แยกออกจากคำสั่งที่ตายตัว
อธิบายว่าการผูกชื่อเข้ากับช่องว่างใน SQL เปลี่ยนแปลงอะไรไป
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
คำสั่งยังคงตายตัวในขณะที่ค่าที่ถูกผูกแยกต่างหากยังคงเป็นข้อมูล
Placeholders จะผูกค่า ดังนั้นชื่อตารางและทิศทางการจัดเรียงควรมาจาก Allowlist ที่กำหนดไว้ล่วงหน้าบนเซิร์ฟเวอร์เท่านั้น
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ถูกต้อง Placeholders ไม่สามารถทำหน้าที่แทน Identifiers ได้อย่างปลอดภัย ควรเลือก Dynamic identifiers จากตัวเลือกที่ปลอดภัยและทราบแล้วบนเซิร์ฟเวอร์
Run a complete local example
- Save and run this Python example using SQLite. The unusual string is stored as a name, then searched as a bound value.
- The result contains only that named row. Binding prevents this value becoming SQL syntax; it does not establish permission or make every application secure.
import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE students (id INTEGER PRIMARY KEY, name TEXT)")
name = "' OR 1=1 --"
con.executemany("INSERT INTO students VALUES (?, ?)", [(1, "Mei"), (2, name)])
rows = con.execute("SELECT id FROM students WHERE name = ?", (name,)).fetchall()
print(rows) # [(2,)]
con.close()
ตัวอย่าง SQLite แบบสมบูรณ์จะพิมพ์อะไร?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
สตริงที่ไม่ปกติจะถูกจัดเก็บและจับคู่เป็นชื่อตามตัวอักษร
Keep failures useful and private
- Give the browser a clear message it can act on, such as an invalid field or a temporary failure. Do not return raw SQL errors, private credentials or stack traces.
- Record diagnostic details only in protected logs with sensitive values removed. Log enough context to investigate without copying every private request body.
ส่งข้อความความผิดพลาดจากฐานข้อมูลดิบให้กับผู้เยี่ยมชมทั่วไปเพื่อให้พวกเขาสามารถแก้ไข SQL ได้เอง
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ส่งข้อความที่ปลอดภัยและมีประโยชน์; ปกป้องบันทึกการวินิจฉัยและลบค่าที่อ่อนไหวออก
Verify more than a happy path
- Check valid, missing, wrong-type and oversized input; denied access; an empty match; and a simulated database failure. State the expected result for each.
- Keep every dynamic value bound, including dropdown values. The browser’s list does not prevent someone sending a different value directly.
Validate the request, authorize the caller and bind data values. These solve different problems; none replaces the others.
อินพุตภายนอกใดที่ต้องการตรวจสอบจากเซิร์ฟเวอร์? เลือกทุกข้อที่เกี่ยวข้อง
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ค่าภายนอกที่ดูปกติก็ยังคงมีประเภท ความยาว หรือสิทธิ์ที่ผิดได้
คำขอข้อมูลมีการกำหนดพารามิเตอร์ แต่ผู้เรียกใช้งานรายใดก็อ่านแถวข้อมูลนักเรียนที่เป็นความลับได้ สิ่งที่ขาดหายไปคืออะไร?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
การผูกที่อยู่เพื่อฉีดค่า ไม่ได้อนุญาตให้ผู้เรียกใช้งานเข้าถึงข้อมูล