2026-06-15 15:04:43 -07:00
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
|
import test from 'node:test';
|
|
|
|
|
import { runBasicFileScan } from './mindspace-scan.mjs';
|
|
|
|
|
|
|
|
|
|
test('runBasicFileScan passes plain text files', () => {
|
|
|
|
|
const result = runBasicFileScan(Buffer.from('hello world'), {
|
|
|
|
|
filename: 'note.txt',
|
|
|
|
|
mimeType: 'text/plain',
|
|
|
|
|
});
|
|
|
|
|
assert.equal(result.scanStatus, 'passed');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('runBasicFileScan blocks inline script payloads', () => {
|
|
|
|
|
const result = runBasicFileScan(Buffer.from('<script>alert(1)</script>'), {
|
|
|
|
|
filename: 'note.md',
|
|
|
|
|
mimeType: 'text/markdown',
|
|
|
|
|
});
|
|
|
|
|
assert.equal(result.scanStatus, 'blocked');
|
|
|
|
|
assert.equal(result.riskLevel, 'high');
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-10 20:05:52 +08:00
|
|
|
test('runBasicFileScan warns for sandboxed html with inline script and trusted Chart.js', () => {
|
|
|
|
|
const result = runBasicFileScan(
|
|
|
|
|
Buffer.from(`<!doctype html>
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.7/dist/chart.umd.min.js"></script>
|
|
|
|
|
<script>new Chart(document.createElement('canvas'), { type: 'bar', data: { labels: [] } });</script>`),
|
|
|
|
|
{
|
|
|
|
|
filename: 'dashboard.html',
|
|
|
|
|
mimeType: 'text/html',
|
|
|
|
|
htmlActiveContentPolicy: 'sandbox_warn',
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
assert.equal(result.scanStatus, 'warned');
|
|
|
|
|
assert.equal(result.riskLevel, 'medium');
|
|
|
|
|
assert.deepEqual(result.findings, ['trusted_html_active_content']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('runBasicFileScan still blocks unsafe html active content in sandbox mode', () => {
|
|
|
|
|
const javascriptUrl = runBasicFileScan(Buffer.from('<a href="javascript:alert(1)">go</a>'), {
|
|
|
|
|
filename: 'dashboard.html',
|
|
|
|
|
mimeType: 'text/html',
|
|
|
|
|
htmlActiveContentPolicy: 'sandbox_warn',
|
|
|
|
|
});
|
|
|
|
|
assert.equal(javascriptUrl.scanStatus, 'blocked');
|
|
|
|
|
assert.deepEqual(javascriptUrl.findings, ['javascript_url']);
|
|
|
|
|
|
|
|
|
|
const unknownScript = runBasicFileScan(
|
|
|
|
|
Buffer.from('<script src="https://evil.example/app.js"></script>'),
|
|
|
|
|
{
|
|
|
|
|
filename: 'dashboard.html',
|
|
|
|
|
mimeType: 'text/html',
|
|
|
|
|
htmlActiveContentPolicy: 'sandbox_warn',
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
assert.equal(unknownScript.scanStatus, 'blocked');
|
|
|
|
|
assert.deepEqual(unknownScript.findings, ['text_active_content']);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-15 15:04:43 -07:00
|
|
|
test('runBasicFileScan blocks suspicious zip compression ratio', () => {
|
|
|
|
|
const buffer = Buffer.alloc(64);
|
|
|
|
|
buffer.write('PK', 0);
|
|
|
|
|
buffer.writeUInt16LE(8, 8);
|
|
|
|
|
buffer.writeUInt32LE(10, 18);
|
|
|
|
|
buffer.writeUInt32LE(5000, 22);
|
|
|
|
|
const result = runBasicFileScan(buffer, {
|
|
|
|
|
filename: 'report.docx',
|
|
|
|
|
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
|
|
|
});
|
|
|
|
|
assert.equal(result.scanStatus, 'blocked');
|
|
|
|
|
});
|