XMLインジェクションとLDAPインジェクションの防止
SQLやコマンドだけでなく、XML(XXE)やLDAPに対するインジェクション対策も学びます。信頼できない入力がこれらのインタープリターを破壊する仕組みと、無害化する方法を理解します。
「XMLインジェクションとLDAPインジェクションの防止」はCoddyKit上の無料Secure Coding & OWASP Top 10 for Backendレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSecure Coding & OWASP Top 10 for Backend学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Secure Coding & OWASP Top 10 for Backendコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Injection Beyond SQL
You have seen SQL, command, and XSS injection. Any interpreter that mixes untrusted input with structure is at risk. Two often-missed backend targets are XML parsers and LDAP directories.
What Is XXE
XML External Entity (XXE) injection abuses XML parsers that resolve external entities. An attacker defines an entity that reads a local file or hits an internal URL.
<!DOCTYPE x [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
<data>&xxe;</data>What XXE Can Do
- Read sensitive files from the server
- Perform server-side request forgery to internal services
- Cause denial of service via entity expansion
All from a parser feature most apps never need.
Disable External Entities
The core fix is to configure the parser to not resolve external entities or DTDs. This single setting closes XXE entirely.
factory.setFeature('http://apache.org/xml/features/disallow-doctype-decl', true);
factory.setExpandEntityReferences(false);Prefer Safer Formats
Where possible, accept JSON instead of XML — it has no entity concept and no equivalent attack. If you must take XML, lock the parser down first.
What Is LDAP Injection
LDAP directories are queried with filter strings. If user input is concatenated into a filter, an attacker can alter the query logic — the LDAP analog of SQL injection.
// vulnerable: input goes straight into the filter
filter = '(uid=' + username + ')'An LDAP Bypass
Submitting * or admin)(&) as a username can turn a precise filter into one that matches many entries or always succeeds, bypassing authentication.
Escape LDAP Special Characters
Neutralize the special characters * ( ) \ NUL by escaping them before they enter a filter.
def escape(s):
out = ''
for ch in s:
if ch in '*()\\':
out += '\\' + format(ord(ch), '02x')
else:
out += ch
return outUse Parameterized APIs
Best of all, use directory APIs that accept inputs as parameters rather than building filter strings by hand — the same principle that makes prepared SQL statements safe.
The Common Defense
Across SQL, command, XML, and LDAP the rule is identical: never let untrusted input change the structure of a query or document. Separate code from data with parameterization, escaping, or safe parser config.
Allow-List Validation
Add a layer of defense by validating input against an allow-list of acceptable values before it reaches any interpreter. Rejecting unexpected characters or formats early shrinks the attack surface for every injection class at once.
import re
if not re.fullmatch(r'[a-zA-Z0-9_.-]+', username):
raise ValueError('invalid username')Quick Check
Test your injection defense.
Recap
You extended injection defense to XML and LDAP:
- XXE abuses external entities — disable DTDs and entity resolution
- LDAP injection manipulates filters — escape special characters or use parameterized APIs
- The universal rule: keep untrusted data out of structure
AI チューターと学ぶ Secure Coding & OWASP Top 10 for Backend — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「XMLインジェクションとLDAPインジェクションの防止」レッスンは無料ですか?
はい。「XMLインジェクションとLDAPインジェクションの防止」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Secure Coding & OWASP Top 10 for Backendコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Secure Coding & OWASP Top 10 for Backendコースには全4レッスンが含まれています。
「XMLインジェクションとLDAPインジェクションの防止」で何を学びますか?
SQLやコマンドだけでなく、XML(XXE)やLDAPに対するインジェクション対策も学びます。信頼できない入力がこれらのインタープリターを破壊する仕組みと、無害化する方法を理解します。 ブラウザで直接実行するハンズオンコードでSecure Coding & OWASP Top 10 for Backendを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Secure Coding & OWASP Top 10 for Backendを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSecure Coding & OWASP Top 10 for Backendは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「XMLインジェクションとLDAPインジェクションの防止」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSecure Coding & OWASP Top 10 for Backendレッスンでコードを書いて実行できますか?
はい。すべてのSecure Coding & OWASP Top 10 for Backendレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- SQLインジェクションの防止
- コマンドインジェクションとコードインジェクション
- バックエンドにおけるクロスサイトスクリプティング(XSS)
- XMLインジェクションとLDAPインジェクションの防止