Secure Coding & OWASP Top 10 for Backend · Lezione

Prevenire le injection XML e LDAP

Estenda la difesa dalle injection oltre SQL e comandi, includendo XML (XXE) e LDAP. Impari come gli input non attendibili possano corrompere questi interpreti e come neutralizzarli.

Lezione 4 di 413 passaggi

Prevenire le injection XML e LDAP è una lezione Secure Coding & OWASP Top 10 for Backend gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Secure Coding & OWASP Top 10 for Backend, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Secure Coding & OWASP Top 10 for Backend include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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 out

Use 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
Gratis per iniziare

Impara Secure Coding & OWASP Top 10 for Backend con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
12
Lezioni
48

Domande Frequenti

La lezione «Prevenire le injection XML e LDAP» è gratuita?

Sì — il testo completo di «Prevenire le injection XML e LDAP» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Secure Coding & OWASP Top 10 for Backend, passa a CoddyKit PRO. Il corso Secure Coding & OWASP Top 10 for Backend include 4 lezioni in totale.

Cosa imparerò in «Prevenire le injection XML e LDAP»?

Estenda la difesa dalle injection oltre SQL e comandi, includendo XML (XXE) e LDAP. Impari come gli input non attendibili possano corrompere questi interpreti e come neutralizzarli. Eserciti Secure Coding & OWASP Top 10 for Backend con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Secure Coding & OWASP Top 10 for Backend?

Non è richiesta alcuna esperienza precedente. Secure Coding & OWASP Top 10 for Backend su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Prevenire le injection XML e LDAP»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Secure Coding & OWASP Top 10 for Backend?

Sì. Ogni lezione Secure Coding & OWASP Top 10 for Backend include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Prevenzione della SQL injection
  2. Command injection e code injection
  3. Cross-Site Scripting (XSS) nel backend
  4. Prevenire le injection XML e LDAP
← Torna a Secure Coding & OWASP Top 10 for Backend