CVE-2021-43856 (JavaScript, published 2021-12-27T18:15Z)
Description: value: Wiki.js is a wiki app built on Node.js. Wiki.js 2.5.263 and earlier is vulnerable to stored cross-site scripting through non-image file uploads for file types that can be viewed directly inline in the browser. By creating a malicious file which can execute inline JS when viewed in the browser (e.g. XML files), a malicious Wiki.js user may stage a stored cross-site scripting attack. This allows the attacker to execute malicious JavaScript when the file is viewed directly by other users. The file must be opened directly by the user and will not trigger directly in a normal Wiki.js page. A patch in version 2.5.264 fixes this vulnerability by adding an optional (enabled by default) force download flag to all non-image file types, preventing the file from being viewed inline in the browser. As a workaround, disable file upload for all non-trusted users. --- Thanks to @Haxatron for reporting this vulnerability. Initially reported via https://huntr.dev/bounties/266bff09-00d9-43ca-a4bb-bb540642811f/
Severity: LOW (CVSS v3 base score: 5.4)
Weakness: CWE-79 \u2014 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
Repository: https://github.com/Requarks/wiki
Files changed:
client/components/admin/admin-security.vue
server/app/data.yml
server/graph/resolvers/site.js
server/graph/schemas/site.graphql
server/helpers/asset.js
server/models/assets.js
Commit message: fix: force download of unsafe extensions


Vulnerable code:
        uploadScanSVG: WIKI.config.uploads.scanSVG
          scanSVG: _.get(args, 'uploadScanSVG', WIKI.config.uploads.scanSVG)

Fixed code:
                  v-divider.mt-3
                  v-switch(
                    inset
                    label='Force Download of Unsafe Extensions'
                    color='primary'
                    v-model='config.uploadForceDownload'
                    persistent-hint
                    hint='Should non-image files be forced as downloads when accessed directly. This prevents potential XSS attacks via unsafe file extensions uploads.'
                    )
        uploadForceDownload: true,
              $uploadForceDownload: Boolean
                  uploadForceDownload: $uploadForceDownload,
            uploadForceDownload: _.get(this.config, 'uploadForceDownload', false),
              uploadForceDownload
      forceDownload: true
        uploadScanSVG: WIKI.config.uploads.scanSVG,
        uploadForceDownload: WIKI.config.uploads.forceDownload
          scanSVG: _.get(args, 'uploadScanSVG', WIKI.config.uploads.scanSVG),
          forceDownload: _.get(args, 'uploadForceDownload', WIKI.config.uploads.forceDownload)
    uploadForceDownload: Boolean
  uploadForceDownload: Boolean
const path = require('path')
  },

  getPathInfo(assetPath) {
    return path.parse(assetPath.toLowerCase())
      const fileInfo = assetHelper.getPathInfo(assetPath)

      // Force unsafe extensions to download
      if (WIKI.config.uploads.forceDownload && !['.png', '.apng', '.jpg', '.jpeg', '.gif', '.bmp', '.webp', '.svg'].includes(fileInfo.ext)) {
        res.set('Content-disposition', 'attachment; filename=' + fileInfo.base)
      }