Skip to content

Commit e3cd4d8

Browse files
committed
fix csrf
1 parent aaae926 commit e3cd4d8

3 files changed

Lines changed: 8 additions & 54 deletions

File tree

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,9 @@
113113
<p>This is a development view of the Bibliographic Framework Initiative project's editor. For more information, go to <a href="http://www.loc.gov/bibframe/">www.loc.gov/bibframe</a>.</p>
114114
</div>
115115
</footer>
116+
<script type="text/javascript">
117+
var bfeditor = bfe.fulleditor(config, "bfeditor");
118+
</script>
119+
116120
</body>
117121
</html>

src/bfe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ bfe.define('src/bfe', ['require', 'exports', 'src/bfestore', 'src/bfelogging', '
537537

538538
$(td).find('#bfeditor-deleteConfirmButton' + rowData.id).click(function () {
539539
if (editorconfig.deleteId.callback !== undefined) {
540-
editorconfig.deleteId.callback(rowData.id, editorconfig.getCSRF.callback(), bfelog);
540+
editorconfig.deleteId.callback(rowData.id, bfelog);
541541
//var table = $('#table_id').DataTable();
542542
// table.row($(this).parents('tr')).remove().draw();
543543
bfestore.store = [];
@@ -1225,7 +1225,7 @@ bfe.define('src/bfe', ['require', 'exports', 'src/bfestore', 'src/bfelogging', '
12251225
save_json.addedproperties = addedProperties;
12261226

12271227
if (_.some(bfeditor.bfestore.store, {'p': 'http://id.loc.gov/ontologies/bibframe/mainTitle'})) {
1228-
editorconfig.save.callback(save_json, editorconfig.getCSRF.callback(), bfelog, function (save, save_name) {
1228+
editorconfig.save.callback(save_json, bfelog, function (save, save_name) {
12291229
bfelog.addMsg(new Error(), 'INFO', 'Saved: ' + save_name);
12301230
});
12311231
} else {

static/js/config.js

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,7 @@ var ie = (function(){
1717
document.body.scrollTop = document.documentElement.scrollTop = 0;
1818
}
1919

20-
function csrfSafeMethod(method) {
21-
// these HTTP methods do not require CSRF protection
22-
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
23-
}
24-
25-
function getCSRF(){
26-
//eventually you'll have to login
27-
var cookieValue = null;
28-
if (document.cookie && document.cookie != '') {
29-
var cookies = document.cookie.split(';');
30-
for (var i = 0; i < cookies.length; i++) {
31-
var cookie = jQuery.trim(cookies[i]);
32-
var name = "csrftoken";
33-
if (cookie.substring(0, name.length + 1) == (name + '=')) {
34-
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
35-
break;
36-
}
37-
}
38-
}
39-
return cookieValue;
40-
}
41-
42-
function setCSRF(xhr, settings, csrf) {
43-
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
44-
xhr.setRequestHeader("X-CSRFToken", csrf);
45-
}
46-
}
47-
48-
function save(data, csrf, bfelog, callback){
20+
function save(data, bfelog, callback){
4921
var $messagediv = $('<div>', {id: "bfeditor-messagediv", class:"col-md-10 main"});
5022

5123
var url = config.url + "/verso/api/bfs/upsertWithWhere?where=%7B%22name%22%3A%20%22"+data.name+"%22%7D";
@@ -54,7 +26,6 @@ var ie = (function(){
5426
url: url,
5527
type: "POST",
5628
data:JSON.stringify(data),
57-
csrf: csrf,
5829
dataType: "json",
5930
contentType: "application/json; charset=utf-8"
6031
}).done(function (data) {
@@ -212,18 +183,13 @@ var ie = (function(){
212183
}
213184

214185

215-
function deleteId(id, csrf, bfelog){
186+
function deleteId(id, bfelog){
216187
var url = config.url + "/verso/api/bfs/" + id;
217188

218-
//$.ajaxSetup({
219-
// beforeSend: function(xhr, settings){getCSRF(xhr, settings, csrf);}
220-
//});
221-
222189
$.ajax({
223190
type: "DELETE",
224191
url: url,
225192
dataType: "json",
226-
csrf: csrf,
227193
success: function (data) {
228194
bfelog.addMsg(new Error(), "INFO", "Deleted " + id);
229195
},
@@ -464,25 +430,9 @@ var ie = (function(){
464430
"deleteId": {
465431
"callback": deleteId
466432
},
467-
"getCSRF":{
468-
"callback": getCSRF
469-
},
470-
/* "load": [
471-
{
472-
"templateID": ["profile:bf:Work:Monograph", "profile:bf:Instance:Monograph", "profile:bf:Annotation:AdminMeta"],
473-
"defaulturi": "http://id.loc.gov/resources/bibs/5226",
474-
"_remark": "Source must be JSONLD expanded, so only jsonp and json are possible requestTypes",
475-
"source": {
476-
"location": "http://id.loc.gov/resources/bibs/5226.bibframe_raw.jsonp",
477-
"requestType": "jsonp",
478-
"data": "UNUSED, BUT REMEMBER IT"
479-
}
480-
}
481-
],*/
482433
"return": {
483434
"format": "jsonld-expanded",
484435
"callback": myCB
485436
}
486437
}
487-
var bfeditor = bfe.fulleditor(config, "bfeditor");
488438

0 commit comments

Comments
 (0)