Commit 8062daef7543f9a509f209cf95425a05390194eb
1 parent
93b22072
Exists in
master
and in
1 other branch
- added support for xsrf (cross site request forgery)
Showing
4 changed files
with
15 additions
and
10 deletions
Show diff stats
BUGS.md
1 | 1 | |
2 | -BUGS: | |
2 | +# BUGS | |
3 | 3 | |
4 | 4 | - detect questions in questions.yaml without ref -> error ou generate default. |
5 | 5 | - topicos virtuais nao deveriam aparecer. na construção da árvore os sucessores seriam ligados directamente aos predecessores. |
6 | 6 | - Criar outra estrutura organizada em capítulos (conjuntos de tópicos). Permitir capítulos de capítulos, etc. talvez usar grafos de grafos... |
7 | 7 | - error if demo.yaml has no topics |
8 | 8 | - session management. close after inactive time. |
9 | -- implementar xsrf. Ver [http://www.tornadoweb.org/en/stable/guide/security.html#cross-site-request-forgery-protection]() | |
10 | 9 | - generators not working: bcrypt (ver blog) |
11 | 10 | - tabelas nas perguntas radio/checkbox não ocupam todo o espaço como em question. |
12 | 11 | - mover javascript para ficheiros externos e carregar com <script defer src='...'> |
13 | 12 | |
14 | -TODO: | |
13 | +# TODO | |
15 | 14 | |
16 | -- pertuntas tipo tristate: (sim, não, não sei | |
15 | +- update de fontawesome para versão 5. | |
17 | 16 | - reportar comentarios após submeter. |
18 | 17 | - each topic only loads a sample of K questions (max) in random order. |
19 | 18 | - servir imagens/ficheiros. |
19 | +- pertuntas tipo tristate: (sim, não, não sei | |
20 | 20 | - forçar reload das perguntas sem ter de deitar abaixo o servidor. |
21 | -- update de fontawesome para versão 5. | |
22 | 21 | - reload das perguntas enquanto online. |
23 | 22 | - tabela de progresso de todos os alunos por topico. |
24 | 23 | - tabela com perguntas / quantidade de respostas certas/erradas. |
... | ... | @@ -27,12 +26,13 @@ TODO: |
27 | 26 | - implementar servidor http com redirect para https. |
28 | 27 | - usar codemirror no textarea |
29 | 28 | - ao fim de 3 tentativas com password errada, envia email com nova password. |
30 | -- titulos das perguntas não suportam markdown. | |
29 | +- titulos das perguntas não suportam markdown. | |
31 | 30 | - pagina report que permita ver tabela alunos/topicos, estatisticas perguntas mais falhadas, tempo médio por pergunta. |
32 | 31 | - normalizar com perguntations. |
33 | 32 | |
34 | -FIXED: | |
33 | +# FIXED | |
35 | 34 | |
35 | +- implementar xsrf. Ver [http://www.tornadoweb.org/en/stable/guide/security.html#cross-site-request-forgery-protection]() | |
36 | 36 | - se refs de um topic estao invalidos, nao carrega esse topico. devia haver um error nos logs a indicar qual o ref invalido. |
37 | 37 | - link directo para topico nao valida se topico esta unlocked. |
38 | 38 | - templates not working: quesntion-information, question-warning (remove all informative panels??) | ... | ... |
serve.py
... | ... | @@ -37,7 +37,7 @@ class WebApplication(tornado.web.Application): |
37 | 37 | 'template_path': path.join(path.dirname(__file__), 'templates'), |
38 | 38 | 'static_path': path.join(path.dirname(__file__), 'static'), |
39 | 39 | 'static_url_prefix': '/static/', |
40 | - 'xsrf_cookies': False, # FIXME see how to do it... | |
40 | + 'xsrf_cookies': True, | |
41 | 41 | 'cookie_secret': base64.b64encode(uuid.uuid4().bytes), |
42 | 42 | 'login_url': '/login', |
43 | 43 | 'debug': debug, | ... | ... |
templates/maintopics.html
... | ... | @@ -138,10 +138,17 @@ |
138 | 138 | $("#notifications").fadeIn(250).delay(5000).fadeOut(500); |
139 | 139 | } |
140 | 140 | |
141 | + function getCookie(name) { | |
142 | + var r = document.cookie.match("\\b" + name + "=([^;]*)\\b"); | |
143 | + return r ? r[1] : undefined; | |
144 | + } | |
145 | + | |
141 | 146 | function change_password() { |
147 | + var token = getCookie('_xsrf'); | |
142 | 148 | $.ajax({ |
143 | 149 | type: "POST", |
144 | 150 | url: "/change_password", |
151 | + headers: {'X-XSRFToken' : token }, | |
145 | 152 | data: { |
146 | 153 | "new_password": $("#new_password").val(), |
147 | 154 | }, | ... | ... |
templates/topic.html
... | ... | @@ -190,7 +190,6 @@ |
190 | 190 | $.ajax({ |
191 | 191 | type: "GET", |
192 | 192 | url: "/question", |
193 | - // headers: {"X-XSRFToken": token}, | |
194 | 193 | dataType: "json", // expected from server |
195 | 194 | success: updateQuestion, |
196 | 195 | error: function() {alert("O servidor não responde.");} |
... | ... | @@ -203,7 +202,6 @@ |
203 | 202 | $.ajax({ |
204 | 203 | type: "POST", |
205 | 204 | url: "/question", |
206 | - // headers: {"X-XSRFToken": token}, | |
207 | 205 | data: $("#question_form").serialize(), // {'a':10,'b':20}, |
208 | 206 | dataType: "json", // expected from server |
209 | 207 | success: updateQuestion, | ... | ... |