SlideServe
Menu
Préférences
© SlideServe · v2026

CSP : script-nonce

lacota-bailey avatar
16 diapositives · 406 Views · Nov 01, 2014

CSP : script-nonce. Bo Feng, Kun Yu, Yuchun Cui. Content Security Policy.

CSP : script-nonce - slide 1
01 / 16CSP : script-nonce
1 / 17

Télécharger la présentation

CSP : script-nonce
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. CSP : script-nonce Bo Feng, Kun Yu, Yuchun Cui

  2. Content Security Policy • W3C specification offering the possibility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use "directive" where a directive define a loading behavior for a target resource type https://www.owasp.org/index.php/Content_Security_Policy

  3. Set rules in HTTP Response Header • Content-Security-Policy : Defined by W3C as standard header • X-Content-Security-Policy : Firefox & IE • X-WebKit-CSP : Chrome

  4. script-nonce • The script-nonce directive is intended to allow developers to strictly specify exactly which script elements on a page were intentionally included for execution. • HTTP Response Header: • Content-Security-Policy: script-nonce random-value ; • Script tag’s nonce attribute in HTTP Response Content • <script nonce="random-value”> alert("I execute!"); </script> • <script> alert("I don't execute. Boo!"); </script>

  5. Task • Add proper Content-Security-Policy header in HTTP response header • Add nonce attribute in each valid <script> HTML tag

  6. Apache Module • Output filters • Header filter • Body content filter • Filters modify content, then send modified content to next filter in the filter chain filter Our filter Other filters

  7. Header filter • Add CSP header keys for different browsers: • Content-Security-Policy : script-nonce rand-val • X-Content-Security-Policy : script-nonce rand-val • X-WebKit-CSP : script-nonce rand-val

  8. Body content filter • Find <script> tag with some specified nonce value, replace it with new rand-valstring • E.g. • Before replacing it : • <script nonce=‘asdf’> … • <script > … • Aftet replacing it with random value (the same one in the header filter) : • <script nonce=‘randome-value’> … • <script > … // this script will be invalid because of lacking invalid nonce value

  9. Random string generator • PRG function : get random 16 bytes • … • unsigned char ptr[16]; • int fd = open("/dev/random", O_RDONLY); • read(fd, ptr, 16); • close(fd); • …

  10. Random string generator – contd. • PRG function : convert 16 bytes to 32 Hex string : • … • char randstr[32]; • for (i = 0; i < 16; i++) { • sprintf(randstr + i*2, "%02x", *(ptr+i)); • } • …

  11. Random string generator – contd. • E.g. c38f222be2f2f705b386ed6118a59354 • Random value space:1632 = 2128

  12. Header filter output sample

  13. Body content filter output sample

  14. Experiments (script-src)

  15. Experiments (script-nonce)

  16. Experiments (script-src, script-nonce)