Refractoring Stage 7.1 Added sanitizer regression coverage for dangerous nodes and attributes, remote-image URL approval, and keeping remote images inert until explicit loading. Bumped to 0.4.37 (Android version code 437) and updated REFACTOR_PLAN.md.
This commit is contained in:
+2
-1
@@ -153,7 +153,7 @@ This is a gradual destination, not a requirement to move everything at once. IPC
|
||||
- Electron Builder and the desktop Actions artifact name derive from `package.json`.
|
||||
- Android `versionName` derives from the same package version. Its current `versionCode` mapping is `major * 10000 + minor * 100 + patch`; keep minor and patch below 100, and revise the mapping before reaching that boundary to avoid collisions.
|
||||
- `scripts/build-all.ps1` uses the package version for APK naming. Before a release, bump once with `npm run bump:build`, verify the lockfile and computed Android version code, and build every target without another bump.
|
||||
- Latest version check: `package.json` and both lockfile version fields are `0.4.36`; Android derives `versionName 0.4.36` and `versionCode 436`. The user confirms the previous artifact works; this bump is for the next build.
|
||||
- Latest version check: `package.json` and both lockfile version fields are `0.4.37`; Android derives `versionName 0.4.37` and `versionCode 437`. The user confirms the previous artifact works; this bump is for the next build.
|
||||
|
||||
## Progress log
|
||||
|
||||
@@ -192,5 +192,6 @@ This is a gradual destination, not a requirement to move everything at once. IPC
|
||||
- Step 6 at version `0.4.34` removes legacy global renderer-state accessors; the state module now exposes only `window.epMailState` to the renderer.
|
||||
- Step 6 at version `0.4.35` consolidates the mail API factory under `window.epMailFeatures.modules`, removing the separate `window.epMailUiModules` global.
|
||||
- Step 6 at version `0.4.36` consolidates the HTML sanitization and remote-image policy API under `window.epMailFeatures.contentSecurity`.
|
||||
- Step 7 at version `0.4.37` adds focused sanitizer coverage for dangerous DOM nodes/attributes and verifies that remote images remain data-only pending explicit loading.
|
||||
- The current IPC/DAV validation changes pass the full suite: 108 tests.
|
||||
- While work continued, `package.json` and `package-lock.json` reflected a version bump to `0.4.6`; those changes were preserved.
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "ep-mail",
|
||||
"version": "0.4.36",
|
||||
"version": "0.4.37",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "ep-mail",
|
||||
"version": "0.4.36",
|
||||
"version": "0.4.37",
|
||||
"dependencies": {
|
||||
"@capacitor/android": "^8.5.2",
|
||||
"@capacitor/core": "^8.5.2",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ep-mail",
|
||||
"version": "0.4.36",
|
||||
"version": "0.4.37",
|
||||
"private": true,
|
||||
"description": "Eternity Project mail client",
|
||||
"homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client",
|
||||
|
||||
@@ -20,3 +20,60 @@ test('allows only bounded HTTPS remote image URLs without embedded credentials',
|
||||
assert.equal(safeRemoteImageUrl('not a URL'), null);
|
||||
assert.equal(safeRemoteImageUrl(null), null);
|
||||
});
|
||||
|
||||
test('sanitizes parsed mail DOM and keeps approved remote images inert', () => {
|
||||
let parsedHtml = '';
|
||||
const createElement = (localName, attributes = {}, childNodes = []) => {
|
||||
const values = new Map(Object.entries(attributes));
|
||||
const element = {
|
||||
nodeType: 1,
|
||||
localName,
|
||||
childNodes,
|
||||
parentNode: null,
|
||||
get attributes() { return [...values].map(([name, value]) => ({ name, value })); },
|
||||
getAttribute(name) { return values.get(name) ?? null; },
|
||||
setAttribute(name, value) { values.set(name, String(value)); },
|
||||
removeAttribute(name) { values.delete(name); },
|
||||
remove() {
|
||||
if (this.parentNode) this.parentNode.childNodes.splice(this.parentNode.childNodes.indexOf(this), 1);
|
||||
},
|
||||
get innerHTML() {
|
||||
const attributes = [...values].map(([name, value]) => ` ${name}="${value}"`).join('');
|
||||
if (this.localName === 'img') return `<img${attributes}>`;
|
||||
const contents = childNodes.map(child => child.nodeType === 3 ? child.textContent : child.innerHTML).join('');
|
||||
return `<${this.localName}${attributes}>${contents}</${this.localName}>`;
|
||||
}
|
||||
};
|
||||
for (const child of childNodes) child.parentNode = element;
|
||||
return element;
|
||||
};
|
||||
const body = {
|
||||
childNodes: [],
|
||||
get innerHTML() { return this.childNodes.map(child => child.innerHTML).join(''); }
|
||||
};
|
||||
const browserRoot = {
|
||||
Node: { ELEMENT_NODE: 1, TEXT_NODE: 3 },
|
||||
DOMParser: class {
|
||||
parseFromString(html) {
|
||||
parsedHtml = html;
|
||||
const url = html.match(/data-remote-src="([^"]+)"/)?.[1] || '';
|
||||
body.childNodes = [
|
||||
createElement('script', {}, [{ nodeType: 3, textContent: 'alert(1)' }]),
|
||||
createElement('p', { onclick: 'alert(2)' }, [{ nodeType: 3, textContent: 'Hello' }]),
|
||||
createElement('img', { src: url, 'data-remote-src': url, alt: 'pixel', onerror: 'alert(3)' })
|
||||
];
|
||||
body.childNodes.forEach(child => { child.parentNode = body; });
|
||||
return { body };
|
||||
}
|
||||
}
|
||||
};
|
||||
const { html, remoteImageCount } = createMailContentSecurity(browserRoot).sanitizeMailHtml(
|
||||
'<p onclick="alert(2)">Hello</p><script>alert(1)</script><img src="https://images.example.test/pixel.png" onerror="alert(3)"><a href="javascript:alert(4)">link</a>'
|
||||
);
|
||||
|
||||
assert.doesNotMatch(parsedHtml, /<script\b|\shref\s*=|\ssrc\s*=/i);
|
||||
assert.match(parsedHtml, /<img data-remote-src="https:\/\/images\.example\.test\/pixel\.png">/);
|
||||
assert.equal(remoteImageCount, 1);
|
||||
assert.equal(html, '<p>Hello</p><img data-remote-src="https://images.example.test/pixel.png" alt="pixel">');
|
||||
assert.doesNotMatch(html, /onclick|onerror|javascript:|<script/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user