Files
wekan/models/lib/fileResponseSafety.js
T
Lauri Ojansivu ebcd02be6f Hall of Fame regression audit: every fixed vulnerability still fixed, siblings of six of them closed.
Every Hall of Fame vulnerability without a test naming it (24 names, 30
advisories) was checked against the current source. No fix had been
reverted. Looking for the same mistake elsewhere found siblings:

- FloppyBleed: the fs-path-heal upgrade step joined an attachment's
  stored name into candidate paths as-is; a record a client inserted
  named ../../../etc/passwd made the next upgrade copy that file into
  storage - an arbitrary file read. Only the name's last component is
  used now; the bulk move limits a legacy name's extension the same way.
- FilePathBleed (GHSA-g6vm-7757-pr88): the insert guard looked only
  inside versions; with versions left out ostrio:files falls back to a
  top-level path, which removing the record deletes and validation
  reads. A client's top-level path is refused for attachments and
  avatars, recorded by the existing canaries.
- MoveStorageBleed: validateAttachment, which deletes a file failing the
  current upload rules, was open to anybody who could see the board, a
  public one included. Only who may change the file, or a site admin,
  validates now; a refusal is recorded (authz.attachment-validate).
- HookUrlBleed / IntegrationBleed: the REST reads of a board's
  integrations gave the webhook URL - whose path is its secret - to
  every member reading the board; non-admins get what the publication
  gives them.
- AttachmentMigrationBleed: four migration methods answered any
  logged-in user about any board, deleteDuplicateEmptyLists.getStatus
  with a private board's list titles; they require a visible board and
  record refusals (authz.migration-board).
- LegacyAttachBleed (GHSA-xcxp-hx9w-q5q9) and MimeStorageBleed
  (GHSA-rv5g-5p4g-3v89): the legacy route judged a name dangerous only
  for .svg, the response policy missed x-javascript, ecmascript, xsl and
  +xml types, and the sniffers missed <tag/onx= handlers.

OIDCBleed refusals are now recorded in Admin Panel / Problems too. New
suites name the vulnerabilities they guard, existing ones name the
advisories they already covered, and tests/securityRegressionCoverage
counts 128 of 137 published vulnerabilities with a named test (was 125).

Thanks to xet7 !
2026-10-27 16:28:12 +02:00

68 lines
1.8 KiB
JavaScript

'use strict';
const DANGEROUS_MIME_TYPES = new Set([
'text/html',
'application/xhtml+xml',
'image/svg+xml',
'text/xml',
'application/xml',
'application/javascript',
'text/javascript',
// LegacyAttachBleed: the other names browsers give script and XSLT.
'application/x-javascript',
'application/ecmascript',
'text/ecmascript',
'text/xsl',
]);
// Any structured-syntax `+xml` type (application/rss+xml, application/foo+xml)
// is rendered as an XML document, where XHTML-namespaced script runs.
function mimeTypeIsBrowserExecutable(normalizedType) {
return DANGEROUS_MIME_TYPES.has(normalizedType) || /\+xml$/.test(normalizedType);
}
const DANGEROUS_FILE_EXTENSIONS = new Set([
'html',
'htm',
'xhtml',
'svg',
'xml',
'js',
'mjs',
'cjs',
]);
function fileNameIsBrowserExecutable(name) {
const cleanName = String(name || '').split(/[?#]/, 1)[0].toLowerCase();
const dot = cleanName.lastIndexOf('.');
return dot !== -1 && DANGEROUS_FILE_EXTENSIONS.has(cleanName.slice(dot + 1));
}
function fileResponsePolicy(type, dangerousByName = false) {
const normalizedType = String(type || 'application/octet-stream')
.split(';', 1)[0]
.trim()
.toLowerCase();
const dangerous = dangerousByName || mimeTypeIsBrowserExecutable(normalizedType);
return {
contentType: dangerous ? 'application/octet-stream' : normalizedType,
forceDownload: dangerous,
headers: dangerous ? {
'Content-Security-Policy': "default-src 'none'; sandbox;",
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
} : {
'X-Content-Type-Options': 'nosniff',
},
};
}
module.exports = {
DANGEROUS_MIME_TYPES,
DANGEROUS_FILE_EXTENSIONS,
fileNameIsBrowserExecutable,
mimeTypeIsBrowserExecutable,
fileResponsePolicy,
};