Commit Graph

35 Commits

Author SHA1 Message Date
Erik Michelson 6c5b44eaec feat(media): serve uploads from local filesystem with permission check
Previously, the permission checks of the /media/:uuid route could be
bypassed for the local filesystem as a media backend, because the
/media/:uuid route performed a redirect to the target after checking
the permissions. Since the target was always /uploads/:uuid.ext where
ext was the extension of the uploaded file, you could simply try to
guess the file extension and have access to the file since the
/uploads endpoint was simply the complete uploads folder mounted.
Now, media uploads from the local filesystem backend are served
under the /media route directly instead of a redirect.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2026-07-24 22:17:00 +02:00
Erik Michelson 95f28442c3 chore(tests): performance improvements for backend tests
Docker / build-and-push (backend) (push) Has been cancelled
Docker / build-and-push (frontend) (push) Has been cancelled
E2E Tests / backend-sqlite (push) Has been cancelled
E2E Tests / backend-mariadb (push) Has been cancelled
E2E Tests / backend-postgres (push) Has been cancelled
Lint and check format / Lint files and check formatting (push) Has been cancelled
REUSE Compliance Check / reuse (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Static Analysis / Njsscan code scanning (push) Has been cancelled
Static Analysis / CodeQL analysis (javascript) (push) Has been cancelled
Run tests & build / Test and build with NodeJS 24 (push) Has been cancelled
The backend end-to-end tests run with many parallel workers that
each start a full NestJS application including database connection
pools, HTTP server and so on. This can easily result in performance
bottlenecks - which is even the reason why we added the --runInBand
option for the CI. The performance can be improved by constraining
the number of workers and memory allocated per worker in our jest
config. Furthermore, we can forcefully close open HTTP connections
in the test cleanup. This terminates connections with a keepalive
flag, that would persist for a while longer otherwise. The following
`this.app.close()` waits for keepalive requests, so this reduces the
wait time.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2026-04-15 19:34:53 +02:00
Philip Molares 57234ee810 feat(backend): set charset to utf8mb4 for mariadb
Docker / build-and-push (backend) (push) Has been cancelled
Docker / build-and-push (frontend) (push) Has been cancelled
E2E Tests / backend-sqlite (push) Has been cancelled
E2E Tests / backend-mariadb (push) Has been cancelled
E2E Tests / backend-postgres (push) Has been cancelled
Lint and check format / Lint files and check formatting (push) Has been cancelled
REUSE Compliance Check / reuse (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Static Analysis / Njsscan code scanning (push) Has been cancelled
Static Analysis / CodeQL analysis (javascript) (push) Has been cancelled
Run tests & build / Test and build with NodeJS 24 (push) Has been cancelled
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2026-03-29 12:27:03 +02:00
Philip Molares 5eb15e43d8 feat(username): allow mixed case usernames
Usernames should be saved as is, but in the search we should use like

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2026-03-24 12:49:12 +01:00
Philip Molares 2a2bd92265 feat(alias): allow mixed case aliases
Aliases should be saved as is, but in the search we should use like

Co-authored-by: Erik Michelson <github@erik.michelson.eu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2026-03-24 12:49:12 +01:00
Philip Molares 6e4470b626 feat(knex): extend knex with whereEqualLowercase
This allows us to reuse the same logic instead of copying it all over the place

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2026-03-24 12:49:12 +01:00
Erik Michelson a99f99d6ac feat(security): add rate limiting
This adds rate-limiting using the @fastify/rate-limit module with sane
default values, configuration options, the possibility to disable limits
and differentiation between logged-in users and unauthenticated requests.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2026-02-04 22:13:07 +01:00
Erik Michelson 66d052d611 feat(security): add CSRF protection to private API endpoints
This adds a new endpoint /api/private/csrf/token which serves a CSRF-token that
is stored in the user's session. Following requests with POST, PUT, PATCH or DELETE
request methods, need to provide this token in the CSRF-Token header. Since this
is not possible to do via HTML forms or other cross-site effects, this prevents
cross-site attacks. The frontend loads the CSRF token on app initialization and
stores it in the redux. It keeps using the token for up to one hour and then
updates the stored token from the API endpoint again.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2026-02-04 21:36:52 +01:00
Erik Michelson ac2255579f refactor(backend): switch from express to fastify
Fastify is a more modern web framework than express. Although it
shares almost the same API it has a way better performance and
supports more modern features. Several modules like csurf for
CSRF-protection aren't maintained for express anymore but there
is a Fastify replacement.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2026-02-04 21:36:52 +01:00
Erik Michelson 5574d23889 chore(format): reformat using oxfmt
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2026-01-14 19:46:27 +01:00
Erik Michelson a880864b2c chore(lint): replace ESLint with OXLint for performance
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2026-01-14 19:46:27 +01:00
Philip Molares 0a34f11e29 test(explore): allow some notes to be publiclyVisible
For our testing it necessary to allow some notes to be publicly visible

Co-authored-by: Erik Michelson <github@erik.michelson.eu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2026-01-11 20:21:00 +01:00
Philip Molares adb0d71c2c test: add e2e test for explore api
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2026-01-11 20:21:00 +01:00
Philip Molares ec8eb4d43e fix(test-setup): testId can't contain '-'
As uuidv4 contain '-', but databases we want to support don't,
we need to change the testId.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2025-12-17 20:27:48 +01:00
Philip Molares b7f76b73e2 refactor(test-setup): force databases to return datetime as string
As we need to handle datetime in a very specific way,
we need to force strings as the db output.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2025-12-17 20:27:48 +01:00
Philip Molares 224d02fde9 refactor(test-setup): add asAdmin flag to getTestDatabaseConfig
As we want to create a new databases for each test, we need to login
as the root / admin user into the DB in the setup.
This extra flag allows us to create a true admin knex instance in the
createTestDatabase method

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2025-12-17 20:27:48 +01:00
Philip Molares 0cff118d7e refactor(datetime): add utility methods for datetime
As we encountered problems with different databases, it's
easier if we have one implementation that is used around
our codebase.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2025-12-17 20:27:48 +01:00
Philip Molares e79442bc1b test(e2e): fix public api
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2025-12-17 20:27:48 +01:00
Erik Michelson dc83e15e8f chore(deps): replace old mysql package with mysql2
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-11-06 00:55:21 +01:00
Erik Michelson a12eb4a98f test(backend): update e2e tests for knex database integration
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-11-06 00:55:21 +01:00
Erik Michelson 9d7bde167c chore(esdoc): update and unify ESDoc and parameter names (1)
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-11-06 00:55:21 +01:00
Erik Michelson c39d2f4988 refactor: replace TypeORM with knex.js
Co-authored-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-11-06 00:55:21 +01:00
Erik Michelson b677331171 feat(knex): create database interfaces and knexjs nest integration
Co-authored-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2025-11-06 00:55:21 +01:00
Philip Molares b11dbd51c8 refactor(backend): use @hedgedoc/commons DTOs
Co-authored-by: Erik Michelson <github@erik.michelson.eu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2025-03-29 22:09:01 +01:00
Erik Michelson b24f8b0a76 refactor(auth): rename identity-module to auth-module
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2024-12-18 20:02:19 +01:00
Erik Michelson 2c6717e1ee refactor(api-token): drop passport, rename to ApiToken
We don't need a library that requires as much boilerplate code as
writing the AuthGuard ourselves, especially since the token validation
was already custom code by us.

The previous name PublicAuthToken was a bit misleading, since PublicAuth
 could also be interpreted as being used for the public frontend in
contrast to the API. The old name before that (AuthToken) wasn't better
since it wasn't clear what type of auth is meant. I know, this is the
second renaming of the same module in less than a month. However, I
would say the name ApiToken seems rather reasonable and understandable.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2024-09-18 19:14:32 +02:00
Erik Michelson 7f665fae4b feat(auth): refactor auth, add oidc
Thanks to all HedgeDoc team members for the time discussing,
helping with weird Nest issues, providing feedback
and suggestions!

Co-authored-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2024-09-11 21:29:49 +02:00
Erik Michelson 73d9c3231b refactor(backend): rename auth to public-auth-token
Signed-off-by: Yannick Bungers <git@innay.de>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
2024-09-02 10:33:08 +02:00
David Mehren f8f198f9c9 feat: add initial database migration
Signed-off-by: David Mehren <git@herrmehren.de>
2023-10-08 17:58:32 +02:00
Yannick Bungers f362d27d3f Move session entity to sessions folder
Signed-off-by: Yannick Bungers <git@innay.de>
2023-07-06 12:07:44 +02:00
Tilman Vatteroth ac825edbe3 fix: replace RouterModule from nest-router with @nestjs/core
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-06-16 23:00:06 +02:00
David Mehren 944304b274 test(setup): use HD_BASE_URL
Signed-off-by: David Mehren <git@herrmehren.de>
2023-02-19 20:56:18 +01:00
David Mehren 679d8a8655 refactor(default-access-level): rename from default-access-permission
Signed-off-by: David Mehren <git@herrmehren.de>
2023-02-19 20:56:18 +01:00
David Mehren 4ade25036e test(setup): set HD_DOMAIN
Signed-off-by: David Mehren <git@herrmehren.de>
2023-02-19 20:56:18 +01:00
Tilman Vatteroth bf30cbcf48 fix(repository): Move backend code into subdirectory
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2022-10-30 22:46:42 +01:00