Commit Graph

693 Commits

Author SHA1 Message Date
Joakim Svensson
c3e078c9c6 Add Invite Agent action to editor menu and allow CSP connect-src 2025-12-31 00:08:30 +00:00
Erik Michelson
35f36fccba fix(auth): add state parameters and PKCE support
Only the OAuth2 auth strategy was using the state parameter,
which should be used as described in the RFC. The other
auth strategies such as GitHub, GitLab or Google were lacking
the state parameter.
This change adds the required state parameter as well as
enabling PKCE support on providers where it's possible.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-12-05 22:06:30 +01:00
Philip Molares
bc2075ae9d refactor: use user-token for historyDelete too
Previously, the user token was only used for the endpoint
to delete the user itself. This commit adds that token to
the history deletion as well.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2025-11-26 19:28:53 +01:00
Erik Michelson
9a45d1e2a9 chore(deps): upgrade dependencies, remove some unnecessary ones
This commit upgrades dependencies that are more or less trivial
to update, e.g. because they didn't have major version bumps or
simply didn't break anything. There are some dependencies which
have not been upgraded since this would have required larger
refactorings. This includes especially the markdown-it ecosystem
and the webpack ecosystem.
The largest refactorings in this commit come from the bump of
socket.io v2 to v4 which changed the handling of the connected
socket list for instance.

This commit further removes some outdated and/or unnecessary
dependencies. This includes the String.js library which is
unmaintained for 9 years and has some CVEs. We mainly used
this library for their escapeHTML and unescapeHTML methods.
This can be done using native DOM APIs nowadays, which is also
considered more safe since it is the same logic that the
browser itself uses.
Since we target Node 18 and above, we can also rely on the
built-in fetch function instead of the node-fetch package.
The current version of Chance.js includes a method for
generating a random color now too, so we don't need the
package randomcolor anymore.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-11-24 14:32:24 +01:00
Erik Michelson
637c451486 fix: use nanoid instead of shortid
shortid is deprecated and they recommend nanoid instead.
We're not sure if this has to do with possible name
collisions or enumerability, but to be sure and on the
safe side, we're changing this. nanoid seems quite safe
since it uses node's crypto module underneath.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-11-22 01:05:50 +01:00
Erik Michelson
6d970dbafd feat(config): allow restriction and disabling of uploads
Previously, image uploads were always allowed, unless `CMD_ALLOW_ANONYMOUS=false` and `CMD_ALLOW_ANONYMOUS_EDITS=false`.
This PR adds a new config option `CMD_ENABLE_UPLOADS` to configure image uploads independently. There are three different modes: `all` (everyone can upload, guests too), `registered` (only registered and logged-in users can upload images), and `none` to completely disable image uploads.
The default value is non-breaking as it is `all`, unless the config `CMD_ALLOW_ANONYMOUS=false` and `CMD_ALLOW_ANONYMOUS_EDITS=false` is set, in which case the value is `registered`.
The UI will reflect the setting and either show or hide the upload button.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-11-15 22:54:57 +01:00
Daniel Koschützki
c94ccfb6de fix: Dont return toobusy errors for healthchecks.
If running with an orchestrator that restarts hedgedoc on failing
healthchecks, this causes it to enter a crashloop.

toobusy -> gets restarted -> everyone refreshes -> toobusy

Signed-off-by: Daniel Koschützki <daniel.koschuetzki@adfinis.com>
2025-08-14 15:31:09 +02:00
Erik Michelson
ce66f33a6d feat(config): warning if both saml signing options are disabled
Co-authored-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-04-10 00:21:55 +02:00
Erik Michelson
3f520ea59a refactor(embeds): drop slideshare, use vimeo api, tighten CSP
The slideshare integration was broken for quite a while already,
as slideshare doesn't seem to have a good replacement, we're
dropping it in the same manner as speakerdeck was dropped some
time ago. This means the special syntax now just renders a plain
link. This commit gets rid of the vimdo oembed API too which
allowed JSONP injection. Instead we're using the normal vimeo
video metadata API.

Co-authored-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-04-10 00:21:55 +02:00
Erik Michelson
0636b5c20b refactor: use iframes for gist embedding instead of gist-embed
The used library gist-embed relies on GitHub Gist's JSONP
endpoint which is a risk for XSS injection. By adding untrusted
content from GitHub into the DOM it also follows very bad
practises. Using the iframe embedding has the disadvantage of
not having the proper height for the frame auto-loaded, but
the security benefits are worth it.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-04-10 00:21:55 +02:00
Erik Michelson
cc74351846 feat(saml): add config options to set required signings
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-04-09 21:49:00 +02:00
Philip Molares
a8d5cb754c fix(oauth2): verify user id exists
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2025-02-14 21:09:03 +01:00
Erik Michelson
fb6218ed82 fix(saml): change SAML attribute default, verify that a NameID is defined
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2025-02-14 21:09:03 +01:00
Erik Michelson
1a5030dbc1 fix(saml): adapt for new package @node-saml/passport-saml
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-02-14 21:09:03 +01:00
Erik Michelson
72c233b233 fix: set HSTS preload attribute to false by default
See <https://hstspreload.org/#opt-in> for more information
why this is important.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-02-01 22:56:38 +01:00
Philip Molares
c437366c33 chore(eslint): run eslint --fix
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2025-02-01 22:15:54 +01:00
Erik Michelson
6e9940c85f refactor: use common error message
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-02-01 21:12:08 +01:00
Erik Michelson
876ebad1f3 feat: rate-limiting
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-02-01 21:12:08 +01:00
Dominik Rimpf
980bc71a65 fix(csp): allow 'data:' images in pads
Signed-off-by: Dominik Rimpf <dev@drimpf.de>
2024-12-18 19:09:05 +01:00
Lautaro Alvarez
4fdab806a3 fix(oauth2): Fix crash when profile fields are missing (#5850)
Co-authored-by: Lautaro Alvarez <lautaro@grava.digital>
2024-11-01 15:21:10 +01:00
David Mehren
380587b7fd Ensure case-sensitive DB queries on MySQL/MariaDB
MySQLs string comparisons are case-insensitive by default.
This allows to hide notes by creating a new note with an alias that
equals the lower-cased alias of another note.
The new note is returned first by MySQL, so the original one is not
accessible anymore.

This fixes the problem by using an explicit binary comparison in the
affected queries.

See https://dev.mysql.com/doc/refman/8.0/en/case-sensitivity.html

Signed-off-by: David Mehren <git@herrmehren.de>
2024-09-01 13:54:18 +02:00
David Mehren
1f8f09c539 fix(deps): use meta-marked from NPM
Signed-off-by: David Mehren <git@herrmehren.de>
2024-08-31 18:44:35 +02:00
Erik Michelson
858d7bf5d1 feat: option to disable note creation
The abuse of the demo instance required us to disallow note creation

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2024-07-21 11:03:35 +02:00
Erik Michelson
c85b11463d fix(minio): metadata as object not string
A change in the minio JS SDK resulted in uploads being stored
with a defect metadata object in minio, resulting in all
files served as application/octet-stream. This was caused as
the fifth argument to putObject is a metadata object and not
the content-type alone anymore.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2024-06-20 21:58:17 +02:00
Sheogorath
1f1b2bd386 fix(oauth2): Fix crash in rolesClaim extraction
This patch adds a try-catch around the rolesClaim extraction to prevent
full crashes of HedgeDoc when a user profile is read, that doesn't
contain any such claim, which can happen with some IdPs, like Keycloak,
that omit the attribute when it's empty.

As a result an authorized user would crash the entire server, which is
definitely unintended behaviour. The simply try-catch should resolve the
issue and make sure that roles is always defined even if the
`extractProfileAttribute` call fails.

Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
2023-10-19 19:34:44 +02:00
Tilman Vatteroth
cd26aaa86e fix: use better already-exist check in note creation
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-07-18 23:18:21 +02:00
Tilman Vatteroth
d856c0acb5 fix: accept request body only if string
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-07-18 23:18:21 +02:00
Tilman Vatteroth
e7327afbae fix: don't create notes if not found in presentation route
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-07-18 21:13:29 +02:00
Dennis Gaida
e371d6dcfa Update dockerSecret.js
Adding OAUTH2 secrets so they can be set using docker secrets.

Signed-off-by: Dennis Gaida <2392217+DennisGaida@users.noreply.github.com>
2023-06-09 17:03:17 +02:00
Erik Michelson
143864b8d9 enhancement(metrics): allow disabling via config option
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2023-06-04 21:03:46 +02:00
Julian Rother
2eb4c8e05f Fix premature note cleanup on error
Connection forbidden errors cause cleanup of note state without first
checking if other clients are still connected to the note. This leads
to inconsistent pad content and changes not being saved properly.

This change reverts parts of 725e982 (Fix realtime on forbidden not clean
up properly ...). The call to `interruptConnection()` on permission errors
is redundant, since `failConnection()` and `disconnect()` already perform
all required cleanup in this case. The other call to `interruptConnection()`
only happens when a client (the first client for a note) disconnects while
the note is being loaded from the database. It is refactored for clarity.

Fixes #3894

Co-authored-by: David Mehren <git@herrmehren.de>
Signed-off-by: Julian Rother <julian@jrother.eu>
2023-05-28 16:10:51 +02:00
Erik Michelson
9949e3a875 feat(healthcheck): add /_health endpoint
This endpoint returns the internal readiness state used by
the realtime code to indicate whether HedgeDoc is performing
properly. As it only returns the state of a variable, it is
less resource hungry compared to a call to /status for
checking the health of HedgeDoc.

By prepending the route with an underscore, it should not be conflicting with already created pads in FreeURL mode.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2023-03-19 22:09:16 +01:00
Jordi Mallach
9bda8f2180 Allow setting documentMaxLength via CMD_DOCUMENT_MAX_LENGTH
Signed-off-by: Jordi Mallach <jordi@igalia.com>
2023-03-09 10:20:42 +01:00
Tilman Vatteroth
e2b84e134a fix: extend parsing of boolean environment vars
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-03-02 21:12:27 +01:00
Tilman Vatteroth
fec5e09664 fix(image-router): correct usage of rimraf
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-02-12 20:58:02 +01:00
Stéphane Maniaci
488e5f8a0a Revert "config: Add a flag to control the /metrics and /status endpoints"
This reverts commit d10ead4c6c.

Signed-off-by: Stéphane Maniaci <stephane.maniaci@beta.gouv.fr>
2023-02-05 20:39:13 +01:00
Stéphane Maniaci
d10ead4c6c config: Add a flag to control the /metrics and /status endpoints
It can be a security concern in some environments to expose system
capabilities even though they don't expose any PII. Add some
flags (defaulted `true` to maintain existing behaviour) to control
whether the /metrics and /status (and anything in the StatusRouter)
are exposed.

Signed-off-by: Stéphane Maniaci <stephane.maniaci@beta.gouv.fr>
2023-01-31 10:26:41 +01:00
Erik Michelson
0a9939cfb4 fix(user-export): sanitize filenames in zip properly
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2022-11-27 20:51:37 +01:00
David Mehren
f606a7825f refactor(migrations): move cleanup code into migration
We cannot execute the cleanup script as a subprocess with sqlite,
as we now wrap the migrations in a SAVEPOINT, which blocks a second
process.

This moves the cleanup code into the migration file, so it can be
executed in-process.

Signed-off-by: David Mehren <git@herrmehren.de>
2022-11-06 22:24:48 +01:00
David Mehren
c83eb7ec7e style(migrations): fix formatting errors
Signed-off-by: David Mehren <git@herrmehren.de>
2022-11-06 22:24:48 +01:00
Philip Molares
638c2f6740 fix(migrations): don't run with foreign keys activated
This PR deactivates and reactivates the foreign_keys in the DB for the duration of all migrations.
This prevents a cascade of deletion, when table columns are changed and tables get recreated by sequelize.

Fixes #2809

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2022-11-06 22:24:48 +01:00
David Mehren
63f33f1737 Fix express deprecation warning
Signed-off-by: David Mehren <git@herrmehren.de>
2022-10-30 22:15:16 +01:00
David Mehren
3aeb2a619b Pass through breaks option to published note
The markdown for the publish-view is generated
using the `Note.extractMeta` method.
It uses meta-marked to separate the metadata from markdown.
Only the raw markdown is then sent to the client,
so it cannot respect the `breaks` option.

This adds an evil hack to send the `breaks` option with the markdown
if it is contained in the metadata block.

Fixes https://github.com/hedgedoc/hedgedoc/issues/2358

Signed-off-by: David Mehren <git@herrmehren.de>
2022-10-03 20:18:16 +02:00
Tilman Vatteroth
68466f6f09 fix: Change data type of history attribute in user table to long text
When using mysql the normal text attribute has a fixed size. When this size is reached then the json will be cut off and becomes invalid.

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2022-09-25 11:09:23 +02:00
Tilman Vatteroth
9254c0dc39 Convert history attribute in user table to longtext
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2022-09-25 11:09:23 +02:00
David Mehren
9ab8bf3cac Fix crash in LDAP authentication
Since https://github.com/vesse/node-ldapauth-fork/commit
/741a648df98d789856b3301d65103b74872fdeea, ldapauth-fork calls `push` on
 the attributes array.

 Since we deep-freeze our config object in https://github
 .com/hedgedoc/hedgedoc/blob/master/lib/config/index.js#L200, this
 causes a crash.

 This commit fixes the crash by creating a mutable clone of the LDAP
 config and passing that to the LDAP strategy.

 Fixes https://github.com/hedgedoc/hedgedoc/issues/2561

Signed-off-by: David Mehren <git@herrmehren.de>
2022-08-22 09:01:04 +02:00
Lautaro Alvarez
3585dc9ee6 Upload file to s3: make public a file on upload and allow to configure destination folder
New configurations:
- s3folder: (string) folder to save the files inside bucket
- s3publicFiles: (boolean) indicate if should send ACL parameters

Signed-off-by: Lautaro Alvarez <lautarolalvarez@gmail.com>
2022-07-10 17:44:17 +02:00
Renovate Bot
0e8631a5dc fix(deps): update dependency passport to ^0.6.0
Signed-off-by: Renovate Bot <bot@renovateapp.com>
Signed-off-by: David Mehren <git@herrmehren.de>
2022-06-05 22:36:55 +02:00
Sheogorath
dd539273fb fix(migrations): Remove unexpected shell call
This patch removes the call of `/usr/bin/env` when calling the migration
script in favour of using the processes own nodejs invocation path.

This should drop the requirement for `/usr/bin/env` to exist on a
system/in a container that runs hedgedoc.

Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
2022-05-17 14:04:02 +02:00
David Mehren
d26dcd04a1 Adapt code for eslint-config-standard 17
Signed-off-by: David Mehren <git@herrmehren.de>
2022-05-01 21:19:44 +02:00