Skip to content

Commit 2d54270

Browse files
committed
Removed unsafe-eval necessity for addon to improve security, closes #17
1 parent a297b40 commit 2d54270

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ copyDevFunction()
2020
prepareChromeFunction()
2121
{
2222
echo "Preparing manifest.json for Chrome"
23-
sed -i -e '28,32d;19d;35d' ./dev/manifest.json
23+
sed -i -e '27,31d;35d' ./dev/manifest.json
2424
}
2525

2626
packageChromeFunction()

js/popup.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,32 @@ function fetchGeoLocation() {
5151
});
5252
}
5353

54+
function compileHtml(html, obj, clip) {
55+
for (var prop in obj) {
56+
html = html.replace(new RegExp(clip + prop + clip, 'g'), obj[prop] ? obj[prop] : '');
57+
}
58+
return html;
59+
}
60+
5461
function triggerView() {
55-
var infosHtml = _.template($('#ipGeoLocationView').html());
56-
compiledInfosHtml = infosHtml({
57-
gl: geoIpV4 ? geoIpV4.toJSON() : new GeoLocation(),
58-
gl6: geoIpV6 ? geoIpV6.toJSON() : new GeoLocation6()
59-
});
62+
var infosHtml = $('#ipGeoLocationView').html();
63+
var gIPv4 = (geoIpV4 ? geoIpV4.toJSON() : new GeoLocation().toJSON());
64+
var gIPv6 = (geoIpV6 ? geoIpV6.toJSON() : new GeoLocation6().toJSON());
65+
compiledInfosHtml = compileHtml(infosHtml, gIPv4.geoLocation, 'T');
66+
compiledInfosHtml = compileHtml(compiledInfosHtml, gIPv4.browser, 'T');
67+
compiledInfosHtml = compileHtml(compiledInfosHtml, gIPv6.geoLocation, 'T6');
68+
compiledInfosHtml = compileHtml(compiledInfosHtml, gIPv6.browser, 'T6');
6069
$('#ipLocationInfo').html(compiledInfosHtml);
6170

6271
if (geoIpV4 && geoIpV4.toJSON().geoLocation && geoIpV4.toJSON().geoLocation.latitude != 0) {
63-
var mapHtml = _.template($('#ipGeoMapView').html());
64-
compiledMapHtml = mapHtml({
65-
gl: geoIpV4.toJSON()
66-
});
72+
var mapHtml = $('#ipGeoMapView').html();
73+
compiledMapHtml = compileHtml(mapHtml, geoIpV4.toJSON().geoLocation, 'T');
6774
$('#mapIPV4').html(compiledMapHtml);
6875
}
6976

70-
if(geoIpV6 && geoIpV6.toJSON().geoLocation && geoIpV6.toJSON().geoLocation.latitude != 0) {
71-
var mapHtml = _.template($('#ipGeoMapView').html());
72-
compiledMapHtml = mapHtml({
73-
gl: geoIpV6.toJSON()
74-
});
77+
if (geoIpV6 && geoIpV6.toJSON().geoLocation && geoIpV6.toJSON().geoLocation.latitude != 0) {
78+
var mapHtml = $('#ipGeoMapView').html();
79+
compiledMapHtml = compileHtml(mapHtml, geoIpV6.toJSON().geoLocation, 'T');
7580
$('#mapIPV6').html(compiledMapHtml);
7681
}
7782
}

manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "IP Address & Geolocation",
3-
"version": "2.0.3",
3+
"version": "2.1.0",
44
"manifest_version": 2,
55
"icons": {
66
"16": "img/icon16.png",
@@ -23,7 +23,7 @@
2323
"default_popup": "popup.html",
2424
"default_title": "IP Address & Geolocation"
2525
},
26-
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
26+
"content_security_policy": "script-src 'self'; object-src 'self'",
2727
"applications": {
2828
"gecko": {
2929

popup.html

+13-13
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h2 class="mdl-card__title-text">IP Address & Geolocation</h2>
5050

5151
<script type="text/html" id="ipGeoMapView">
5252
<a class="mdl-button mdl-js-button mdl-button--icon" title="Open location in OpenStreetMap"
53-
href="http://www.openstreetmap.org/?mlat=<%- gl.geoLocation.latitude %>&mlon=<%- gl.geoLocation.longitude %>&zoom=12" target="_blank">
53+
href="http://www.openstreetmap.org/?mlat=TlatitudeT&mlon=TlongitudeT&zoom=12" target="_blank">
5454
<i class="material-icons">map</i>
5555
</a>
5656
</script>
@@ -67,33 +67,33 @@ <h2 class="mdl-card__title-text">IP Address & Geolocation</h2>
6767
<tbody>
6868
<tr>
6969
<td class="mdl-data-table__cell--non-numeric">IP</td>
70-
<td class="mdl-data-table__cell--non-numeric"><%- gl.geoLocation ? gl.geoLocation.ipAddress : null %></td>
71-
<td class="mdl-data-table__cell--non-numeric"><%- gl6.geoLocation ? gl6.geoLocation.ipAddress : null %></td>
70+
<td class="mdl-data-table__cell--non-numeric">TipAddressT</td>
71+
<td class="mdl-data-table__cell--non-numeric">T6ipAddressT6</td>
7272
</tr>
7373
<tr>
7474
<td class="mdl-data-table__cell--non-numeric">City</td>
75-
<td class="mdl-data-table__cell--non-numeric"><%- gl.geoLocation ? gl.geoLocation.city : null %></td>
76-
<td class="mdl-data-table__cell--non-numeric"><%- gl6.geoLocation ? gl6.geoLocation.city : null %></td>
75+
<td class="mdl-data-table__cell--non-numeric">TcityT</td>
76+
<td class="mdl-data-table__cell--non-numeric">T6cityT6</td>
7777
</tr>
7878
<tr>
7979
<td class="mdl-data-table__cell--non-numeric">Country</td>
80-
<td class="mdl-data-table__cell--non-numeric"><%- gl.geoLocation ? gl.geoLocation.countryName : null %></td>
81-
<td class="mdl-data-table__cell--non-numeric"><%- gl6.geoLocation ? gl6.geoLocation.countryName : null %></td>
80+
<td class="mdl-data-table__cell--non-numeric">TcountryNameT</td>
81+
<td class="mdl-data-table__cell--non-numeric">T6countryNameT6</td>
8282
</tr>
8383
<tr>
8484
<td class="mdl-data-table__cell--non-numeric">Continent</td>
85-
<td class="mdl-data-table__cell--non-numeric"><%- gl.geoLocation ? gl.geoLocation.continent : null %></td>
86-
<td class="mdl-data-table__cell--non-numeric"><%- gl6.geoLocation ? gl6.geoLocation.continent : null %></td>
85+
<td class="mdl-data-table__cell--non-numeric">TcontinentT</td>
86+
<td class="mdl-data-table__cell--non-numeric">T6continentT6</td>
8787
</tr>
8888
<tr>
8989
<td class="mdl-data-table__cell--non-numeric">Timezone</td>
90-
<td class="mdl-data-table__cell--non-numeric"><%- gl.geoLocation ? gl.geoLocation.timezone : null %></td>
91-
<td class="mdl-data-table__cell--non-numeric"><%- gl6.geoLocation ? gl6.geoLocation.timezone : null %></td>
90+
<td class="mdl-data-table__cell--non-numeric">TtimezoneT</td>
91+
<td class="mdl-data-table__cell--non-numeric">T6timezoneT6</td>
9292
</tr>
9393
<tr>
9494
<td class="mdl-data-table__cell--non-numeric">User agent</td>
95-
<td class="mdl-data-table__cell--non-numeric"><%- gl.geoLocation ? gl.browser.userAgent : null %></td>
96-
<td class="mdl-data-table__cell--non-numeric"><%- gl6.geoLocation ? gl6.browser.userAgent : null %></td>
95+
<td class="mdl-data-table__cell--non-numeric">TuserAgentT</td>
96+
<td class="mdl-data-table__cell--non-numeric">T6userAgentT6</td>
9797
</tr>
9898
</tbody>
9999
</table>

0 commit comments

Comments
 (0)