HedgeDoc - Ideas grow better together
Find a file
Sheogorath 44b7f607a5
Fix Relative Path Traversal Attack on note creation
Impact
---

An attacker can read arbitrary `.md` files from the server's filesystem due to an [improper input validation](https://cwe.mitre.org/data/definitions/20.html), which results in the ability to perform a [relative path traversal](https://cwe.mitre.org/data/definitions/23.html).

CVSSv3 string: AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N

PoC / Quicktest
---

To verify if you are affected, you can try to open the following URL: `http://localhost:3000/..%2F..%2FREADME#` (replace `http://localhost:3000` with your instance's base-URL e.g. `https://demo.hedgedoc.org/..%2F..%2FREADME#`).
- If you see a README page being rendered, you run an affected version.

Analysis
---

The attack works due the fact that [the internal router, passes the url-encoded alias](https://github.com/hedgedoc/hedgedoc/blob/master/lib/web/note/router.js#L26) to the `noteController.showNote`-function. This function passes the input directly to [`findNote()`](78a732abe6/lib/web/note/util.js (L10)) utility function, that will pass it on the the [`parseNoteId()`](78a732abe6/lib/models/note.js (L188-L258))-function, that tries to make sense out of the noteId/alias and check if a note already exists and if so, if a corresponding file on disk was updated.

If no note exists the [note creation-function is called](78a732abe6/lib/models/note.js (L240-L245)), which pass this unvalidated alias, with a `.md` appended, into a [`path.join()`-function](78a732abe6/lib/models/note.js (L99)) which is read from the filesystem in the follow up routine and provides the pre-filled content of the new note.

This allows an attacker to not only read arbitrary `.md` files from the filesystem, but also  observes changes to them.

The usefulness of this attack can be considered limited, since mainly markdown files are use the file-ending `.md` and all markdown files contained in the hedgedoc project, like the README, are public anyway. If other protections such as a chroot or container or proper file permissions are in place, this attack's usefulness is rather limited.

Workarounds
---
On a reverse-proxy level one can force a URL-decode, which will prevent this attack because the router will not accept such a path.

For more information
---

If you have any questions or comments about this advisory:
* Open an topic on [our community forum](https://community.hedgedoc.org)
* Join our [matrix room](https://chat.hedgedoc.org)

Advisory link
---

https://github.com/hedgedoc/hedgedoc/security/advisories/GHSA-p528-555r-pf87

Signed-off-by: Christoph (Sheogorath) Kern <sheogorath@shivering-isles.com>
2021-04-25 20:40:17 +02:00
.github Update actions/setup-node action to v2 2021-02-05 20:59:08 +00:00
bin Update link to config docs in setup script 2021-03-06 10:36:24 +01:00
docs Update dependency mkdocs-material to v7.0.6 2021-03-14 14:36:35 +00:00
lib Fix Relative Path Traversal Attack on note creation 2021-04-25 20:40:17 +02:00
locales
public Merge pull request #1022 from hedgedoc/fix/translate 2021-03-18 21:36:24 +01:00
test Linter: Fix all lint errors 2021-02-15 12:15:14 +01:00
.babelrc
.editorconfig
.eslintignore
.eslintrc.js
.gitignore
.mailmap
.remarkrc
app.js Run database migrations automatically on startup 2021-02-27 21:33:05 +01:00
app.json
AUTHORS
CHANGELOG.md
CODE-OF-CONDUCT.md
config.json.example
CONTRIBUTING.md Fix link to DCO in contributing docs 2021-01-22 18:10:47 +01:00
LICENSE
package.json Update dependency css-loader to v5.1.3 2021-03-15 20:33:24 +00:00
README.md
renovate.json
SECURITY.md
webpack.common.js Update webpack config and JS import for spin.js v4 2021-02-12 23:47:58 +01:00
webpack.dev.js Use named import for webpack-merge 2021-02-12 22:43:31 +01:00
webpack.htmlexport.js
webpack.prod.js Use named import for webpack-merge 2021-02-12 22:43:31 +01:00
yarn.lock Update dependency css-loader to v5.1.3 2021-03-15 20:33:24 +00:00

HedgeDoc Logo

HedgeDoc

#HedgeDoc on matrix.org version POEditor Mastodon

HedgeDoc lets you create real-time collaborative markdown notes. You can test-drive it by visiting our HedgeDoc demo server.

It is inspired by Hackpad, Etherpad and similar collaborative editors. This project originated with the team at HackMD and now forked into its own organisation. A longer writeup can be read in the history.

HedgeDoc 1.7.0 with its feature demonstration page open

Community and Contributions

We welcome contributions! There's a lot to do: If you would like to report bugs, the issue tracker is the right place. If you can help translating, find us on POEditor. To get started developing, take a look at the developer documentation. In any case: come talk to us, we'll be delighted to help you with the first steps.

To stay up to date with our work or get support it's recommended to join our Matrix channel, stop by our community forums or subscribe to the release feed. We also engage in regular community calls (RSS) which you are very welcome to join.

Installation / Upgrading

You can run HedgeDoc in a number of ways, and we created setup instructions for all of these:

Configuration

Theres two main ways to configure your HedgeDoc instance: config file or environment variables. You can choose what works best for you.

HedgeDoc can integrate with

  • facebook, twitter, github, gitlab, mattermost, dropbox, google, ldap, saml and oauth2 for login
  • imgur, s3, minio, azure for image/attachment storage (files can also be local!)
  • dropbox for export and import

More info about that can be found in the configuration docs above.

Browser support

To use HedgeDoc, your browser should match or exceed these versions:

  • Chrome Chrome >= 47, Chrome Chrome for Android >= 47
  • Safari Safari >= 9, iOS Safarai iOS Safari >= 8.4
  • Firefox Firefox >= 44
  • Edge Edge >= 12
  • Opera Opera >= 34, Opera Mini Opera Mini not supported
  • Android Browser Android Browser >= 4.4

Backup/restore your instance

To backup HedgeDoc, you should:

  • backup your database
  • backup your custom config file if you have one
  • backup the upload folder (see the uploadsPath config directive)

Restoring an existing instance of HedgeDoc is then just a matter of restoring these elements.

Our community has created related tools, we'd like to highlight hedgedoc-cli which lets you use HedgeDoc from the comfort of your command line.

License

Licensed under AGPLv3. For our list of contributors, see AUTHORS.

The license does not include the HedgeDoc logo, whose terms of usage can be found in the github repository.