mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
60 lines
2.7 KiB
JavaScript
60 lines
2.7 KiB
JavaScript
/* eslint-env mocha */
|
|
// MimeBleed and MimeStorageBleed - upload-side MIME and active-content guards.
|
|
// Named for tests/securityRegressionCoverage.test.cjs, which checks the published
|
|
// Hall of Fame list against the tests that guard it - a test that does not say
|
|
// which vulnerability it belongs to cannot be checked against that list.
|
|
|
|
import { expect } from 'chai';
|
|
import { looksLikeDangerousMarkup } from '/models/fileValidation';
|
|
|
|
// Regression test for GHSA-jhph-whx8-wq6p: when the `file` binary is unavailable,
|
|
// isFileValid() must not trust the client-supplied MIME type. It falls back to
|
|
// looksLikeDangerousMarkup() to sniff the real bytes, so a spoofed "image/png"
|
|
// upload that actually contains HTML/JS is still forced through the dangerous
|
|
// content scan (and rejected). These tests pin the sniffer that gates that path.
|
|
describe('fileValidation — dangerous-markup content sniff (GHSA-jhph-whx8-wq6p)', function() {
|
|
describe('flags dangerous markup regardless of the claimed MIME type', function() {
|
|
const dangerous = [
|
|
"<html><body><script>alert('XSS')</script></body></html>",
|
|
'<script>document.cookie</script>',
|
|
'<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>',
|
|
' \n <html></html>', // leading whitespace
|
|
'<!DOCTYPE html><html></html>',
|
|
"<?xml version='1.0'?><root/>",
|
|
'<iframe src="evil"></iframe>',
|
|
'<object data="x"></object>',
|
|
'<embed src="x">',
|
|
'<!ENTITY xxe SYSTEM "file:///etc/passwd">',
|
|
'<META HTTP-EQUIV="refresh" content="0">', // case-insensitive
|
|
'<img/onerror=document.body.dataset.executed="yes" src=x>',
|
|
'<img src=x onerror=alert(1)>', // unquoted handler
|
|
'<a href=javascript:alert(1)>open</a>',
|
|
];
|
|
dangerous.forEach((sample, i) => {
|
|
it(`detects dangerous sample #${i + 1}`, function() {
|
|
expect(looksLikeDangerousMarkup(sample)).to.equal(true);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('does NOT misfire on genuine non-markup content (negative)', function() {
|
|
const safe = [
|
|
'',
|
|
null,
|
|
undefined,
|
|
'hello world, this is a plain text note.',
|
|
'a,b,c\n1,2,3\n', // CSV
|
|
'{"key": "value", "n": 1}', // JSON
|
|
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR', // PNG magic bytes
|
|
'\xff\xd8\xff\xe0\x00\x10JFIF', // JPEG magic bytes
|
|
'%PDF-1.7\n1 0 obj', // PDF header
|
|
'Some text mentioning a script for a play, no angle brackets.',
|
|
];
|
|
safe.forEach((sample, i) => {
|
|
it(`treats safe sample #${i + 1} as not dangerous`, function() {
|
|
expect(looksLikeDangerousMarkup(sample)).to.equal(false);
|
|
});
|
|
});
|
|
});
|
|
});
|