Skip to content

Commit

Permalink
Update Sniffer for better detect injected data; prepared for reuse co…
Browse files Browse the repository at this point in the history
…de in Firefox extension
  • Loading branch information
Sergey Malinin committed Dec 22, 2015
1 parent d6fc527 commit f40216b
Show file tree
Hide file tree
Showing 31 changed files with 487 additions and 235 deletions.
26 changes: 26 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This file is part of the OpenLink Structured Data Sniffer
*
* Copyright (C) 2015 OpenLink Software
*
* This project is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License, dated June 1991.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

var Browser = {
// isFirefox:(!navigator.userAgent.match(/khtml/i) && !!navigator.userAgent.match(/Gecko/i)&& !!navigator.userAgent.match(/Firefox/i)),
// isWebKit:!!navigator.userAgent.match(/AppleWebKit/),
isChromeAPI: true,
isFirefoxSDK: false
}
26 changes: 26 additions & 0 deletions browser_ff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This file is part of the OpenLink Structured Data Sniffer
*
* Copyright (C) 2015 OpenLink Software
*
* This project is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License, dated June 1991.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

var Browser = {
// isFirefox:(!navigator.userAgent.match(/khtml/i) && !!navigator.userAgent.match(/Gecko/i)&& !!navigator.userAgent.match(/Firefox/i)),
// isWebKit:!!navigator.userAgent.match(/AppleWebKit/),
isChromeAPI: false,
isFirefoxSDK: true
}
164 changes: 104 additions & 60 deletions handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Namespace.prototype = {


Handle_Microdata = function () {
var callback = null;
this.callback = null;
};

Handle_Microdata.prototype = {
Expand All @@ -154,40 +154,63 @@ Handle_Microdata.prototype = {



Handle_Turtle = function () {
var callback = null;
var baseURI = null;
Handle_Turtle = function (start_id) {
this.callback = null;
this.baseURI = null;
this._pos = 0;
this._output = null;
this.start_id = 0;
if (start_id!==undefined)
this.start_id = start_id;
};

Handle_Turtle.prototype = {

parse : function(textData, docURL, callback) {
this.callback = callback;
this.baseURI = docURL;

var store = new N3DataConverter();
var parser = N3.Parser();
var self = this;
try {
parser.parse(textData,
function (error, tr, prefixes) {
if (error) {
self.error = ""+error;
self.callback(self.error, null);
}
else if (tr) {
store.addTriple(self.fixNode(tr.subject),
self.fixNode(tr.predicate),
self.fixNode(tr.object));
}
else {
var str = new HTML_Gen().load(store.output);
self.callback(null, str);
}
});
} catch (ex) {
self.callback(ex.toString(), null);

if (this._pos < textData.length) {
var store = new N3DataConverter();
var parser = N3.Parser();
try {
parser.parse(textData[self._pos],
function (error, tr, prefixes) {
if (error) {
self.error = ""+error;
self.callback(self.error, null);
}
else if (tr) {
store.addTriple(self.fixNode(tr.subject),
self.fixNode(tr.predicate),
self.fixNode(tr.object));
}
else {
if (self._output===null)
self._output = "";

var triples = store.output;

self._output += new HTML_Gen().load(triples, self.start_id);
self._pos++;

if (triples!==null && triples.length!==undefined)
self.start_id+= triples.length;

if (self._pos < textData.length)
self.parse(textData, docURL, self.callback);
else
self.callback(null, self._output);
}
});
} catch (ex) {
self.callback(ex.toString(), null);
}
} else {
self.callback(null, this._output);
}

},


Expand Down Expand Up @@ -215,48 +238,69 @@ Handle_Turtle.prototype = {


Handle_JSONLD = function () {
var callback = null;
this.callback = null;
this._pos = 0;
this._output = null;
this.start_id = 0;
};

Handle_JSONLD.prototype = {

parse : function(textData, docURL, callback) {
this.callback = callback;
var self = this;
try {
jsonld_data = JSON.parse(textData);
if (jsonld_data != null) {
jsonld.expand(jsonld_data,
function(err, expanded) {
if (err) {
self.callback(""+err, null);
}
else {
jsonld.toRDF(expanded, {format: 'application/nquads'},
function(err, nquads) {
if (err) {
self.callback(""+err, null);
}
else {
var handler = new Handle_Turtle();
handler.parse(nquads, docURL, function(error, html_data) {
if (error) {
self.callback(""+error, null);
}
else {
self.callback(null, html_data);
}
});
}
});
}
})

if (this._pos < textData.length)
{
try {
jsonld_data = JSON.parse(textData[this._pos]);
if (jsonld_data != null) {
jsonld.expand(jsonld_data,
function(err, expanded) {
if (err) {
self.callback(""+err, null);
}
else {
jsonld.toRDF(expanded, {format: 'application/nquads'},
function(err, nquads) {
if (err) {
self.callback(""+err, null);
}
else {
var handler = new Handle_Turtle(self.start_id);
handler.parse([nquads], docURL, function(error, html_data) {
if (error) {
self.callback(""+error, null);
}
else {
if (self._output===null)
self._output = "";

self._output += html_data;
self._pos++;
self.start_id += handler.start_id;

if (self._pos < textData.length)
self.parse(textData, docURL, self.callback);
else
self.callback(null, self._output);
}
});
}
});
}
})
}
else
self.callback(null, null);
} catch (ex) {
self.callback(ex.toString(), null);
}
else
self.callback(null, null);
} catch (ex) {
self.callback(ex.toString(), null);

} else {
self.callback(null, this._output);
}

}


Expand All @@ -265,7 +309,7 @@ Handle_JSONLD.prototype = {


Handle_RDFa = function () {
var callback = null;
this.callback = null;
};

Handle_RDFa.prototype = {
Expand Down
24 changes: 14 additions & 10 deletions html_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@

HTML_Gen.prototype = {

load: function (json_data)
load: function (n_data, start_id)
{
var expanded = null;
var id_list = {};

if (start_id===undefined)
start_id = 0;

this.uimode = localStorage.getItem("ext.osds.uiterm.mode");
if (this.uimode===null)
this.uimode = "ui-eav";
Expand All @@ -46,21 +49,22 @@
}


if (json_data!=null &&
json_data.length!==undefined &&
json_data.length > 0)
if (n_data!=null &&
n_data.length!==undefined &&
n_data.length > 0)
{
var str = "";
//fill id_list
for(var i=0; i < json_data.length; i++)
for(var i=0; i < n_data.length; i++)
{
id_list[json_data[i].s] = i+1;
id_list[n_data[i].s] = start_id+i+1;
}


for(var i=0; i < json_data.length; i++)
for(var i=0; i < n_data.length; i++)
{
var item = json_data[i];
var item = n_data[i];
var item_num = start_id + item.n;
str += "\
<table class='docdata table'> \
<thead> \
Expand All @@ -70,7 +74,7 @@
</tr> \
</thead> \
<tbody> \
<tr class='major'><td>Statement Collection #"+item.n+"</td><td></td></tr> \
<tr class='major'><td>Statement Collection #"+item_num+"</td><td></td></tr> \
";
str += this.format_id(item.s, id_list);

Expand Down Expand Up @@ -120,7 +124,7 @@

for(var i=0; i<val.length; i++) {
var obj = val[i];
if (obj.iri!=undefined) {
if (obj.iri!==undefined) {
var iri = obj.iri;
var entity_id = id_list[iri];
if (entity_id!==undefined && iri[0]==="_" && iri[1]===":") {
Expand Down
Empty file modified images/throbber.gif
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-icons_222222_256x240.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-icons_2e83ff_256x240.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-icons_454545_256x240.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-icons_888888_256x240.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/images/ui-icons_cd0a0a_256x240.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified lib/css/smoothness/jquery-ui-1.8.6.custom.css
100755 → 100644
Empty file.
Empty file modified lib/jquery-ui-1.8.6.custom.min.js
100755 → 100644
Empty file.
Empty file modified lib/jsuri.js
100755 → 100644
Empty file.
Empty file modified lib/original/jquery.microdata.json.js
100755 → 100644
Empty file.
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
"page_action": {
"default_icon": "images/icon128.png",
"default_title": "Show Document Metadata",
"default_popup": "background.html"
"default_popup": "panel.html"
},
"background": {
"page": "background.html"
"page": "panel.html"
},
"options_page": "options.html",
"content_scripts": [
{
"matches": ["*://*/*"],
"css": [],
"js": ["lib/jquery-1.11.3.min.js", "lib/jquery-migrate-1.2.1.min.js", "lib/jsonld.js", "lib/microdatajs/jquery.microdata.js", "lib/microdatajs/jquery.microdata.json.js", "lib/RDFa.js", "sniffer.js"],
"js": ["lib/jquery-1.11.3.min.js", "lib/jquery-migrate-1.2.1.min.js", "lib/jsonld.js", "lib/microdatajs/jquery.microdata.js", "lib/microdatajs/jquery.microdata.json.js", "lib/RDFa.js", "browser.js", "sniffer.js"],
"run_at": "document_idle"
}
],
Expand Down
6 changes: 3 additions & 3 deletions manifest.json.ff
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"page_action": {
"default_icon": "images/icon128.png",
"default_title": "Show Document Metadata",
"default_popup": "background.html"
"default_popup": "panel.html"
},
"background": {
"page": "background.html"
"page": "panel.html"
},
"content_scripts": [
{
"matches": ["*://*/*"],
"css": [],
"js": ["lib/jquery-1.11.3.min.js", "lib/jquery-migrate-1.2.1.min.js", "lib/jsonld.js", "lib/microdatajs/jquery.microdata.js", "lib/microdatajs/jquery.microdata.json.js", "lib/RDFa.js", "sniffer.js"],
"js": ["lib/jquery-1.11.3.min.js", "lib/jquery-migrate-1.2.1.min.js", "lib/jsonld.js", "lib/microdatajs/jquery.microdata.js", "lib/microdatajs/jquery.microdata.json.js", "lib/RDFa.js", "browser.js", "sniffer.js"],
"run_at": "document_idle"
}
],
Expand Down
Loading

0 comments on commit f40216b

Please sign in to comment.