OAuth2 & OpenID Connect Deep Dive · บทเรียน

การรักษาความปลอดภัย URI เปลี่ยนเส้นทาง

เรียนรู้เหตุผลที่การตรวจสอบ URI เปลี่ยนเส้นทางเป็นหัวใจสำคัญของความปลอดภัย OAuth2 และวิธีป้องกันการโจมตีด้วยตัวเปลี่ยนเส้นทางแบบเปิดและการดักสกัดโค้ด

บทเรียน 4 จาก 413 ขั้นตอน

การรักษาความปลอดภัย URI เปลี่ยนเส้นทาง เป็นบทเรียน OAuth2 & OpenID Connect Deep Dive ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน OAuth2 & OpenID Connect Deep Dive และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส OAuth2 & OpenID Connect Deep Dive มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

The redirect_uri Is Critical

After the user authorizes, the authorization server sends the code (or token) back to the client by redirecting the browser to the redirect_uri. If an attacker can influence that URI, they can steal the code.

Redirect URI validation is therefore one of the highest-impact security controls in OAuth2.

Exact Matching

The single most important rule: the authorization server must compare the supplied redirect_uri against pre-registered values using exact string matching, not pattern or prefix matching.

Registered: https://app.example.com/callback
Request:    https://app.example.com/callback   (OK)
Request:    https://app.example.com/callback/x (REJECT)

Open Redirector Abuse

Loose matching enables open redirector attacks. If https://app.example.com/* is allowed, an attacker may target a page that bounces to an evil host, smuggling the authorization code out.

Wildcards Are Dangerous

Avoid wildcard subdomains and ports. Something like https://*.example.com/cb lets an attacker who controls any subdomain (including user-content subdomains) receive codes.

Always Require HTTPS

Redirect URIs must use https, except for native loopback (http://127.0.0.1) during local development. Plain http over the network exposes the code to interception.

Fragments and Query Tricks

Attackers add fragments (#) or extra query parameters to confuse parsers. Normalize and compare the full registered URI, and reject requests whose redirect_uri carries unexpected components.

Native App Schemes

Native apps often use custom schemes like myapp://callback, but these can be hijacked by another app registering the same scheme. Prefer claimed HTTPS redirects (Universal Links / App Links) which the OS verifies against your domain.

Validating on Both Requests

If a redirect_uri was sent in the authorization request, the same value must be sent at the token request and the server must verify they match. This binds the code to the original client and redirect.

POST /token
grant_type=authorization_code
&code=SplxlOBeZ
&redirect_uri=https://app.example.com/callback   <-- must equal the one used earlier

A Validation Helper

Server-side exact-match check, no normalization shortcuts:

function isAllowed(requested, registeredList) {
  return registeredList.includes(requested);
}
// Reject anything not an exact, literal match.

Combine With PKCE and State

Strict redirect validation pairs with PKCE (so a stolen code is useless without the verifier) and the state parameter (to bind the response to the session). Defense in depth keeps codes safe even if one control slips.

Operational Tips

Keep the registered redirect list short and reviewed. Remove staging URLs from production clients, audit them regularly, and never let users dynamically add arbitrary redirect URIs.

Quick Check

Test your redirect URI security knowledge.

Recap

Securing redirect URIs is foundational:

  • Use exact-match registration; avoid wildcards and prefix matching.
  • Require HTTPS (loopback excepted) and reject odd fragments/params.
  • Re-validate redirect_uri at the token request.
  • Combine with PKCE and state for defense in depth.
เริ่มต้นได้ฟรี

เรียนรู้ OAuth2 & OpenID Connect Deep Dive ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การรักษาความปลอดภัย URI เปลี่ยนเส้นทาง” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การรักษาความปลอดภัย URI เปลี่ยนเส้นทาง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส OAuth2 & OpenID Connect Deep Dive ให้อัปเกรดเป็น CoddyKit PRO คอร์ส OAuth2 & OpenID Connect Deep Dive มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การรักษาความปลอดภัย URI เปลี่ยนเส้นทาง”

เรียนรู้เหตุผลที่การตรวจสอบ URI เปลี่ยนเส้นทางเป็นหัวใจสำคัญของความปลอดภัย OAuth2 และวิธีป้องกันการโจมตีด้วยตัวเปลี่ยนเส้นทางแบบเปิดและการดักสกัดโค้ด คุณปฏิบัติ OAuth2 & OpenID Connect Deep Dive ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน OAuth2 & OpenID Connect Deep Dive หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน OAuth2 & OpenID Connect Deep Dive บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การรักษาความปลอดภัย URI เปลี่ยนเส้นทาง” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน OAuth2 & OpenID Connect Deep Dive นี้ได้ไหม

ได้ บทเรียน OAuth2 & OpenID Connect Deep Dive ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ความปลอดภัยของโทเค็น (เข้าถึงและต่ออายุ)
  2. พารามิเตอร์ state และ CSRF
  3. แนวทางปฏิบัติที่ดีสำหรับประเภทการมอบสิทธิ์
  4. การรักษาความปลอดภัย URI เปลี่ยนเส้นทาง
← กลับไปที่ OAuth2 & OpenID Connect Deep Dive