SimpleLog extended for iframes (#1302)

This commit is contained in:
nobody 2023-01-20 06:48:18 +01:00
parent 9dfdfb79d4
commit 4de7637259
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
7 changed files with 30 additions and 8 deletions

View File

@ -446,6 +446,7 @@ const LogString = {
'MISSING_RESOURCE': 'Missing resource:', 'MISSING_RESOURCE': 'Missing resource:',
'EVIL_RESOURCE_BLOCKED': 'Evil resource blocked:', 'EVIL_RESOURCE_BLOCKED': 'Evil resource blocked:',
'NON_GET_REQUEST_BLOCKED': 'Non-GET-Request blocked', 'NON_GET_REQUEST_BLOCKED': 'Non-GET-Request blocked',
'IFRAME': 'Possible iframe request:',
}; };
// Supported charsets for TextDecoder() // Supported charsets for TextDecoder()

View File

@ -31,7 +31,14 @@ var interceptor = {};
*/ */
interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) { interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
let validCandidate, targetDetails, targetDomain, isGoogleFont, isGoogleMaterialIcons, initiatorDomain, isListed; let validCandidate, targetDetails, targetDomain, isGoogleFont, isGoogleMaterialIcons, initiatorDomain, isListed,
iframe;
iframe = '';
if (tab.url !== requestDetails.originUrl) {
console.log(`${LogString.PREFIX} ${LogString.IFRAME} ${tab.url} -> ${requestDetails.originUrl}`);
iframe = requestDetails.originUrl;
}
if (requestDetails['type'] === WebRequestType.MAIN_FRAME && if (requestDetails['type'] === WebRequestType.MAIN_FRAME &&
helpers.checkAllowlisted( helpers.checkAllowlisted(
@ -57,7 +64,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
// Block POST, HEAD, PUT, DELETE, TRACE, OPTIONS // Block POST, HEAD, PUT, DELETE, TRACE, OPTIONS
if (BlockedRequestMethods[requestDetails.method]) { if (BlockedRequestMethods[requestDetails.method]) {
console.warn(`${LogString.PREFIX} ${LogString.NON_GET_REQUEST_BLOCKED}`); console.warn(`${LogString.PREFIX} ${LogString.NON_GET_REQUEST_BLOCKED}`);
log.append(tab.url, requestDetails.url, LogString.NON_GET_REQUEST_BLOCKED, true); log.append(tab.url, requestDetails.url, LogString.NON_GET_REQUEST_BLOCKED, true, iframe);
return { return {
'cancel': true 'cancel': true
}; };
@ -72,7 +79,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
if (interceptor._isBadResource(requestDetails.url)) { if (interceptor._isBadResource(requestDetails.url)) {
console.log(`${LogString.PREFIX} ${LogString.EVIL_RESOURCE_BLOCKED} ${requestDetails.url}`); console.log(`${LogString.PREFIX} ${LogString.EVIL_RESOURCE_BLOCKED} ${requestDetails.url}`);
log.append(tab.url, requestDetails.url, '-', true); log.append(tab.url, requestDetails.url, '-', true, iframe);
return { return {
'cancel': true 'cancel': true
}; };
@ -105,7 +112,7 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
} }
console.log(`${LogString.PREFIX} ${LogString.REPLACED_RESOURCE} ${targetDetails.path}`); console.log(`${LogString.PREFIX} ${LogString.REPLACED_RESOURCE} ${targetDetails.path}`);
log.append(tab.url, requestDetails.url, targetDetails.path, false); log.append(tab.url, requestDetails.url, targetDetails.path, false, iframe);
return { return {
'redirectUrl': chrome.runtime.getURL(targetDetails.path + fileGuard.secret) 'redirectUrl': chrome.runtime.getURL(targetDetails.path + fileGuard.secret)

View File

@ -21,10 +21,10 @@
var log = {}; var log = {};
log.append = function (initiator, resource, target, highlight) { log.append = function (initiator, resource, target, highlight, iframe = '') {
storageManager.type.get(Setting.LOGGING, function (items) { storageManager.type.get(Setting.LOGGING, function (items) {
if (items.enableLogging) { if (items.enableLogging) {
log.data.push({initiator, resource, target, highlight}); log.data.push({initiator, resource, target, highlight, iframe});
} }
}); });
}; };

View File

@ -24,6 +24,7 @@ table td:first-child {
td { td {
padding: 2px 15px; padding: 2px 15px;
white-space: pre;
} }
textarea { textarea {

View File

@ -38,6 +38,12 @@
<tbody> <tbody>
</tbody> </tbody>
</table> </table>
<br>
<p>
Legend
<br>
<span>(i) = A website includes this iframe. It's possible that the request is from there.</span>
</p>
</div> </div>
</body> </body>
</html> </html>

View File

@ -40,7 +40,7 @@ logging._generateTable = function () {
} }
for (let i = data.length - 1; i >= 0; i--) { for (let i = data.length - 1; i >= 0; i--) {
let tbody, row, cell, content, redirect; let tbody, row, cell, content, redirect, initiator;
tbody = document.getElementById('logging-content').getElementsByTagName('tbody')[0]; tbody = document.getElementById('logging-content').getElementsByTagName('tbody')[0];
row = tbody.insertRow(); row = tbody.insertRow();
@ -53,8 +53,14 @@ logging._generateTable = function () {
content = document.createTextNode(i + 1); content = document.createTextNode(i + 1);
cell.appendChild(content); cell.appendChild(content);
if (Object.values(data[i])[4] === '') {
initiator = Object.values(data[i])[0];
} else {
initiator = `${Object.values(data[i])[0]}\n(i) ${Object.values(data[i])[4]}`;
}
cell = row.insertCell(); cell = row.insertCell();
content = document.createTextNode(Object.values(data[i])[0]); content = document.createTextNode(initiator);
cell.appendChild(content); cell.appendChild(content);
cell = row.insertCell(); cell = row.insertCell();

View File

@ -53,6 +53,7 @@
<p>Improved</p> <p>Improved</p>
<ul> <ul>
<li>Allow Fork-Awesome in Chromium (<a href="https://codeberg.org/nobody/LocalCDN/issues/1296">#1296</a>)</li> <li>Allow Fork-Awesome in Chromium (<a href="https://codeberg.org/nobody/LocalCDN/issues/1296">#1296</a>)</li>
<li>SimpleLog extended for iframes (<a href="https://codeberg.org/nobody/LocalCDN/issues/1302">#1302</a>)</li>
</ul> </ul>
</div> </div>
<div id="generator-section"> <div id="generator-section">