Skip to content

Commit

Permalink
[fix] handle missing file extensions and remove <template> tags
Browse files Browse the repository at this point in the history
  • Loading branch information
asciimoo committed Oct 1, 2024
1 parent 5e82dd4 commit 890cfdb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ext/src/js/modules/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { downloadFile } from './file-download';
import { resources } from './resources';
import { sanitizeCSS } from './sanitize';
import { sanitizeCSS, sanitizeAttributes } from './sanitize';
import {
UrlResolver,
base64Decode,
Expand All @@ -25,6 +25,7 @@ class Document {
}
this.nodeTransformFunctons = new Map([
['SCRIPT', (node) => node.remove()],
['TEMPLATE', (node) => node.remove()],
['LINK', this.transformLink],
['STYLE', this.transformStyle],
['IMG', this.transformImg],
Expand Down Expand Up @@ -66,6 +67,7 @@ class Document {
if (node.nodeType !== Node.ELEMENT_NODE) {
return;
}
sanitizeAttributes(node);
await this.rewriteAttributes(node);
const transformFunction = this.nodeTransformFunctons.get(node.nodeName);
if (transformFunction) {
Expand Down
5 changes: 4 additions & 1 deletion ext/src/js/modules/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class Resource {
this.content = content;
this.mimetype = mimetype;
this.filename = filename;
this.extension = mimetype.split(" ")[0].split("/").pop().toLowerCase().split("+")[0].split(";")[0];
this.extension = 'unknown';
if (mimetype) {
this.extension = mimetype.split(" ")[0].split("/").pop().toLowerCase().split("+")[0].split(";")[0];
}
if (extMap.has(this.extension)) {
this.extension = extMap.get(this.extension);
}
Expand Down
16 changes: 15 additions & 1 deletion ext/src/js/modules/sanitize.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,18 @@ async function sanitizeCSS(rules, baseURL) {
return result;
}

export { sanitizeCSS };
function sanitizeAttributes(el) {
let attrs = [...el.attributes];
for(let i in attrs) {
let key = attrs[i].nodeName;
let val = attrs[i].nodeValue;
if(key.toLowerCase().startsWith("on")) {
el.removeAttribute(key);
}
}
}

export {
sanitizeCSS,
sanitizeAttributes,
};
1 change: 1 addition & 0 deletions ext/src/js/modules/site-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function initComms() {
port.onMessage.addListener((msg, commChan) => {
// TODO generate static extension id and check the full ID, not just the schema
if(!commChan.sender.origin.startsWith('chrome-extension://')) {
console.log("invalid origin");
return;
}
const msgHandler = messageHandlers.get(msg.type);
Expand Down
2 changes: 1 addition & 1 deletion ext/src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "omnom",
"version": "0.11.0",
"version": "0.12.0",
"manifest_version": 3,
"description": "Bookmarking & snapshotting extension for omnom services.",
"content_scripts": [
Expand Down

0 comments on commit 890cfdb

Please sign in to comment.