Cross-site scripting/fr

Les Cross site scripting, ou XSS ou encore injection de JavaScript arbitraire sont un type de faille de sécurité des ordinateurs que l'on trouve typiquement dans les applications web qui permettent aux attaquants d'injecter des  scripts côté client dans les pages web visitées par les autres utilisateurs.

Pour toute information concernant les XSS côté client et comment les empêcher, voir.

Exemples
Exemples de scipts inter-sites :


 * An attacker tricks an authenticated user into visiting a specially crafted URL, or a website which they control which can redirect them to the crafted URL.
 * The URL points to your web app and includes JavaScript in the query string. The web app, due to poor escaping, injects the arbitrary JavaScript into the page that gets shown to the user.
 * The JavaScript runs with full access to the user's cookies. It can modify the page in any way, and it can submit forms on behalf of the user. The risks are especially severe if the victim is an administrator with special privileges.

See Exploit examples on Wikipedia for more examples.

Exemple :

L'attaquant envoie la victime sur une URL telle que :

POST requests are also vulnerable, using offsite JavaScript.

Victims do not even have to directly visit the page to be affected. Malicious 3rd party websites can embed hidden iframes to crafted URLs to attack a user while visiting a website of theirs. As well they may be tricked into visiting a malicious or crafted URL using short URL services or disguising the URL as another.

Arrêter les scripts inter site
To avoid Cross-site scripting do the following:


 * Validez vos entrées
 * Echappez vos sorties

You can skip validation, but you can never skip escaping. Escape everything.

It does not matter if the escaping is redundant with the validation, the performance cost is a small price to pay in exchange for a demonstrably secure web app. It does not matter if the input comes from a trusted source, escaping is necessary even then, because escaping gives you correctness as well as security.

Echappez aussi près que possible de la sortie de sorte à ce que le relecteur puisse vérifier facilement que cela a été fait. Cela vous aide à vérifier également votre propre code également.

L'encodage des sorties est fonction du contexte. Soyez donc conscient du contexte de sortie prévu et encodez de manière appropriée (par exemple l'entité HTML, l'URL, le JavaScript, etc.)

The OWASP Abridged XSS Prevention Cheat Sheet is a useful and up to date quick reference guide for mitigating XSS issues.

All this is true of any text-based interchange format. We concentrate on HTML because web apps tend to generate a lot of it, and because the security issues are particularly severe. Every text format should have a well-studied escaping function.

Here are some convenience functions which do HTML escaping for your site.

Sortie échappée de MediaWiki
MediaWiki also has some elegant built-in interfaces which implicitly escape your output. For SQL using the 'key' => 'value' syntax of conditions implicitly escapes values. And the Html:: and Xml:: interface methods escape attributes, and depending on the method used may escape a text value as well.

Liens externes

 * Escaping, w3.org. Very well written definition of escaping.