Skip to content
This repository was archived by the owner on Sep 5, 2020. It is now read-only.

Commit bed39da

Browse files
authored
ETH-02-cure-fixes #2 (#1477)
* updated package elemeents * fixed max callstack error * remove URL from error page * remove URL from error page * improved url updating * fix ETH-02-003 * added Blaze._escape to the url.protocol * use shorthand for `url: url` * remove function connotation with string. * updated signatures * reverted url shorthand
1 parent a91206d commit bed39da

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

errorPages/400.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
padding-top: 100px;
1515
">
1616
<span style="font-size: 80px;"></span><br>
17-
This URL is not allowed<br>
18-
<br>
19-
<span style="font-family: courier;"><script>document.write(location.search.replace("?",""))</script></span>
17+
This URL is not allowed.
2018
</body>
2119
</html>

interface/client/lib/helpers/helperFunctions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Helpers.generateBreadcrumb = function (url) {
106106
var pathname;
107107

108108
filteredUrl = {
109+
protocol: Blaze._escape(url.protocol),
109110
host: Blaze._escape(url.host),
110111
pathname: Blaze._escape(url.pathname)
111112
};
@@ -114,7 +115,7 @@ Helpers.generateBreadcrumb = function (url) {
114115
return el === '';
115116
});
116117

117-
return new Spacebars.SafeString(_.flatten(['<span>' + filteredUrl.host + ' </span>', pathname]).join(' ▸ '));
118+
return new Spacebars.SafeString(filteredUrl.protocol +'//'+ _.flatten(['<span>' + filteredUrl.host + ' </span>', pathname]).join(' ▸ '));
118119
};
119120

120121
/**

interface/client/templates/views/webview.js

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ The tab template
1515
Template['views_webview'].onRendered(function(){
1616
var template = this,
1717
tabId = template.data._id,
18-
webview = this.find('webview');
18+
webview = template.find('webview');
19+
1920

2021
// Send updated TEST DATA
2122
if(tabId === 'tests') {
@@ -29,6 +30,7 @@ Template['views_webview'].onRendered(function(){
2930
});
3031
}
3132

33+
3234
ipc.on('uiAction_reloadSelectedTab', function(e) {
3335
console.log('uiAction_reloadSelectedTab', LocalStore.get('selectedTab'));
3436
if(LocalStore.get('selectedTab') === this._id){
@@ -53,7 +55,7 @@ Template['views_webview'].onRendered(function(){
5355
// set page history
5456
webview.addEventListener('dom-ready', function(e){
5557

56-
var titleFull = this.getTitle(),
58+
var titleFull = webview.getTitle(),
5759
title = titleFull;
5860

5961
if(titleFull && titleFull.length > 40) {
@@ -64,7 +66,8 @@ Template['views_webview'].onRendered(function(){
6466
// update the title
6567
Tabs.update(tabId, {$set: {
6668
name: title,
67-
nameFull: titleFull
69+
nameFull: titleFull,
70+
// url: webview.getURL(),
6871
}});
6972

7073
webviewLoadStop.call(this, tabId, e);
@@ -83,6 +86,7 @@ Template['views_webview'].onRendered(function(){
8386
}));
8487
});
8588

89+
8690
Template['views_webview'].helpers({
8791
/**
8892
Determines if the current tab is visible
@@ -100,28 +104,44 @@ Template['views_webview'].helpers({
100104
'checkedUrl': function(){
101105
var template = Template.instance();
102106
var tab = Tabs.findOne(this._id, {fields: {redirect: 1}});
107+
var url;
103108

104109
if(tab) {
105110

106111
// set url only once
107112
if(tab.redirect) {
108-
template.url = tab.redirect;
113+
url = tab.redirect;
114+
115+
// remove redirect
116+
Tabs.update(this._id, {$unset: {
117+
redirect: ''
118+
}});
109119
}
110120

111-
// remove redirect
112-
Tabs.update(this._id, {$unset: {
113-
redirect: ''
114-
}, $set: {
115-
url: template.url
116-
}});
117121

118122
// CHECK URL and throw error if not allowed
119-
if(!Helpers.sanitizeUrl(template.url, true)) {
120-
console.log('Not allowed URL: '+ template.url);
121-
return 'file://'+ dirname + '/errorPages/400.html?'+ template.url;
123+
if(!Helpers.sanitizeUrl(url, true)) {
124+
125+
// Prevent websites usingt the history back attacks
126+
if(template.view.isRendered) {
127+
// get the current webview
128+
var webview = template.find('webview');
129+
webview.clearHistory();
130+
}
131+
132+
console.warn('Not allowed URL: '+ template.url);
133+
return 'file://'+ dirname + '/errorPages/400.html';
122134
}
123135

124-
return Helpers.formatUrl(template.url);
136+
// remove redirect
137+
if(url) {
138+
template.url = url;
139+
Tabs.update(this._id, {$set: {
140+
url: url
141+
}});
142+
}
143+
144+
return Helpers.formatUrl(url);
125145
}
126146
}
127-
});
147+
});

interface/client/templates/webviewEvents.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ webviewLoadStart = function(currentTabId, e){
6868

6969
if(e.type === 'did-get-redirect-request' && !e.isMainFrame)
7070
return;
71+
72+
console.log(e.type, currentTabId, e);
7173

7274
// stop this action, as the redirect happens reactive through setting the URL attribute
7375
e.preventDefault(); // doesnt work
7476
webview.stop();
7577
ipc.send('backendAction_stopFocusedWebviewNavigation'); // race condition? cant cancel fast enough sometimes?
76-
77-
console.log(e.type, currentTabId, e);
78+
7879

7980
var url = Helpers.sanitizeUrl(e.newURL || e.url);
8081
var tabId = Helpers.getTabIdByUrl(url);

0 commit comments

Comments
 (0)