Compare commits

...
Author SHA1 Message Date
whoswhip 892624f6ac fix: properly resolve dynamic urls 2026-11-06 08:36:32 -05:00
whoswhip eed65b754e refactor: improve encryption performance and safety
also fixed some issues i saw related to dynamic urls being resolved improperly
formatted via prettier
2026-11-06 08:25:26 -05:00
whoswhip 22c144e970 chore: bump version 2026-10-18 11:59:59 -04:00
whoswhip 336990f5b8 style: separate comments from the paste container 2026-10-18 11:55:39 -04:00
whoswhip 45878d5af1 omfg, actually fix #lib imports 2026-10-18 11:47:06 -04:00
whoswhip 2c43c0b29c chore(deps): update nuget packages for security 2026-10-18 11:24:29 -04:00
whoswhip 0e3a6d97e3 fix: use node env instead of sveltekit env 2026-10-11 22:15:13 -04:00
whoswhip 878457f49d fix #lib 2026-10-10 21:32:51 -04:00
whoswhip 8d060204c8 fix: use #lib instead of $lib 2026-10-10 21:29:02 -04:00
whoswhip f2559eaad0 fix: update TypeScript configuration to extend from $app/tsconfig and adjust include/exclude paths 2026-10-10 21:04:04 -04:00
whoswhip e485b9782b fix node adapter 2026-10-10 20:33:08 -04:00
whoswhip ed7e82adc2 Merge branch 'SharpbinV3' of github.com:whoswhip/Sharpbin into SharpbinV3 2026-10-10 13:34:52 -04:00
whoswhip f8a74d415d Merge pull request #27 from whoswhip/dependabot/npm_and_yarn/SharpbinV3.Client/npm_and_yarn-b9088de85f
chore(deps): bump the npm_and_yarn group across 1 directory with 6 updates
2026-10-10 13:33:41 -04:00
dependabot[bot] 41342efbed chore(deps): bump the npm_and_yarn group across 1 directory with 6 updates
Bumps the npm_and_yarn group with 6 updates in the /SharpbinV3.Client directory:

| Package | From | To |
| --- | --- | --- |
| [dompurify](https://github.com/cure53/DOMPurify) | `3.4.14` | `3.4.16` |
| [sharp](https://github.com/lovell/sharp) | `0.35.4` | `0.35.5` |
| [brace-expansion](https://github.com/juliangruber/brace-expansion) | `1.1.18` | `1.1.21` |
| [cookie](https://github.com/jshttp/cookie) | `0.6.0` | `2.0.1` |
| [handlebars](https://github.com/handlebars-lang/handlebars.js) | `4.7.9` | `4.7.10` |
| [source-map-js](https://github.com/7rulnik/source-map-js) | `1.2.1` | `1.2.2` |



Updates `dompurify` from 3.4.14 to 3.4.16
- [Release notes](https://github.com/cure53/DOMPurify/releases)
- [Commits](https://github.com/cure53/DOMPurify/compare/3.4.14...3.4.16)

Updates `sharp` from 0.35.4 to 0.35.5
- [Release notes](https://github.com/lovell/sharp/releases)
- [Commits](https://github.com/lovell/sharp/compare/v0.35.4...v0.35.5)

Updates `brace-expansion` from 1.1.18 to 1.1.21
- [Release notes](https://github.com/juliangruber/brace-expansion/releases)
- [Commits](https://github.com/juliangruber/brace-expansion/compare/v1.1.18...v1.1.21)

Updates `cookie` from 0.6.0 to 2.0.1
- [Release notes](https://github.com/jshttp/cookie/releases)
- [Commits](https://github.com/jshttp/cookie/compare/v0.6.0...v2.0.1)

Updates `handlebars` from 4.7.9 to 4.7.10
- [Release notes](https://github.com/handlebars-lang/handlebars.js/releases)
- [Changelog](https://github.com/handlebars-lang/handlebars.js/blob/v4.7.10/release-notes.md)
- [Commits](https://github.com/handlebars-lang/handlebars.js/compare/v4.7.9...v4.7.10)

Updates `source-map-js` from 1.2.1 to 1.2.2
- [Release notes](https://github.com/7rulnik/source-map-js/releases)
- [Changelog](https://github.com/7rulnik/source-map-js/blob/main/CHANGELOG.md)
- [Commits](https://github.com/7rulnik/source-map-js/compare/v1.2.1...v1.2.2)

---
updated-dependencies:
- dependency-name: dompurify
  dependency-version: 3.4.16
  dependency-type: direct:production
  dependency-group: npm_and_yarn
- dependency-name: sharp
  dependency-version: 0.35.5
  dependency-type: direct:production
  dependency-group: npm_and_yarn
- dependency-name: brace-expansion
  dependency-version: 1.1.21
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: cookie
  dependency-version: 2.0.1
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: handlebars
  dependency-version: 4.7.10
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: source-map-js
  dependency-version: 1.2.2
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-10-10 03:19:03 +00:00
whoswhip e7a28ea8c0 Merge pull request #26 from whoswhip/dependabot/npm_and_yarn/SharpbinV3.Client/npm_and_yarn-e422db4233
chore(deps): bump devalue from 5.8.1 to 5.9.4 in /SharpbinV3.Client in the npm_and_yarn group across 1 directory
2026-10-09 23:17:00 -04:00
whoswhip e375b0a020 refactor: simplify configuration to a single env file 2026-09-26 19:40:36 -04:00
whoswhip ee8b8f239d docs: fix example secrets 2026-09-26 15:26:00 -04:00
dependabot[bot] eb331f7339 chore(deps): bump devalue
Bumps the npm_and_yarn group with 1 update in the /SharpbinV3.Client directory: [devalue](https://github.com/sveltejs/devalue).


Updates `devalue` from 5.8.1 to 5.9.4
- [Release notes](https://github.com/sveltejs/devalue/releases)
- [Changelog](https://github.com/sveltejs/devalue/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sveltejs/devalue/compare/v5.8.1...v5.9.4)

---
updated-dependencies:
- dependency-name: devalue
  dependency-version: 5.9.4
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-09-26 19:20:42 +00:00
whoswhip b304d8ac9f chore: update node to 24 in ci and docker 2026-09-26 15:19:29 -04:00
whoswhip d45f253c00 fix: normalize cononical 2026-09-14 18:58:28 -04:00
whoswhip b0e9f5104c fix: remove trailing '.' in filename
firefox removes it but chrome sanitizes it to '_'
2026-09-13 18:35:24 -04:00
whoswhip da79f3713a Merge pull request #25 from whoswhip/dependabot/npm_and_yarn/SharpbinV3.Client/npm_and_yarn-c2134247b9
chore(deps): bump the npm_and_yarn group across 1 directory with 2 updates
2026-09-13 18:31:28 -04:00
dependabot[bot] 18e8154248 chore(deps): bump the npm_and_yarn group across 1 directory with 2 updates
Bumps the npm_and_yarn group with 2 updates in the /SharpbinV3.Client directory: [@humanfs/node](https://github.com/humanwhocodes/humanfs/tree/HEAD/packages/node) and [fflate](https://github.com/101arrowz/fflate).


Updates `@humanfs/node` from 0.16.7 to 0.16.8
- [Release notes](https://github.com/humanwhocodes/humanfs/releases)
- [Changelog](https://github.com/humanwhocodes/humanfs/blob/main/packages/node/CHANGELOG.md)
- [Commits](https://github.com/humanwhocodes/humanfs/commits/node-v0.16.8/packages/node)

Updates `fflate` from 0.7.4 to 0.7.5
- [Release notes](https://github.com/101arrowz/fflate/releases)
- [Changelog](https://github.com/101arrowz/fflate/blob/master/CHANGELOG.md)
- [Commits](https://github.com/101arrowz/fflate/commits)

---
updated-dependencies:
- dependency-name: "@humanfs/node"
  dependency-version: 0.16.8
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: fflate
  dependency-version: 0.7.5
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-09-04 22:23:22 +00:00
whoswhip 4e8187c186 Merge pull request #24 from whoswhip/dependabot/npm_and_yarn/SharpbinV3.Client/npm_and_yarn-275026e82a
chore(deps-dev): bump the npm_and_yarn group across 1 directory with 3 updates
2026-09-04 18:21:27 -04:00
dependabot[bot] 5c8f81b951 chore(deps-dev): bump the npm_and_yarn group across 1 directory with 3 updates
Bumps the npm_and_yarn group with 3 updates in the /SharpbinV3.Client directory: [brace-expansion](https://github.com/juliangruber/brace-expansion), [js-yaml](https://github.com/nodeca/js-yaml) and [postcss-selector-parser](https://github.com/postcss/postcss-selector-parser).


Updates `brace-expansion` from 1.1.12 to 1.1.18
- [Release notes](https://github.com/juliangruber/brace-expansion/releases)
- [Commits](https://github.com/juliangruber/brace-expansion/compare/v1.1.12...v1.1.18)

Updates `js-yaml` from 4.2.0 to 4.3.2
- [Changelog](https://github.com/nodeca/js-yaml/blob/4.3.2/CHANGELOG.md)
- [Commits](https://github.com/nodeca/js-yaml/compare/4.2.0...4.3.2)

Updates `postcss-selector-parser` from 7.1.1 to 7.1.5
- [Release notes](https://github.com/postcss/postcss-selector-parser/releases)
- [Changelog](https://github.com/postcss/postcss-selector-parser/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss-selector-parser/compare/v7.1.1...7.1.5)

---
updated-dependencies:
- dependency-name: brace-expansion
  dependency-version: 1.1.18
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: js-yaml
  dependency-version: 4.3.2
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: postcss-selector-parser
  dependency-version: 7.1.5
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-09-03 03:23:33 +00:00
whoswhip e8f2050eb1 chore(deps): update npm packages, add sharp types 2026-09-02 23:21:48 -04:00
whoswhip db492054f7 Merge pull request #22 from whoswhip/dependabot/npm_and_yarn/SharpbinV3.Client/npm_and_yarn-360cad5ee5
chore(deps): bump dompurify from 3.4.9 to 3.4.11 in /SharpbinV3.Client in the npm_and_yarn group across 1 directory
2026-07-16 17:35:46 -04:00
63 changed files with 987 additions and 1222 deletions
+3 -1
View File
@@ -1,6 +1,8 @@
**/.classpath
**/.dockerignore
**/.env
**/backend.env
**/frontend.env
**/.git
**/.gitignore
**/.project
@@ -27,4 +29,4 @@ README.md
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
!.git/refs/heads/**
+26
View File
@@ -0,0 +1,26 @@
# Copy to .env in the repository root. Replace every replace_with_ value before running.
# Generate a different random value for each secret. See README.md for instructions.
# Site
Domain=example.com
Https=true
AllowedCorsOrigins__0=https://example.com
ORIGIN=https://example.com
# Authentication
JwtSettings__Secret=replace_with_a_unique_random_jwt_secret_before_running
# These Turnstile keys are for testing. Use your own site and secret keys in production.
AuthSettings__CF_Turnstile_SecretKey=1x0000000000000000000000000000000AA
AuthSettings__CF_Turnstile_SiteKey=3x00000000000000000000FF
AuthSettings__Registration_Enabled=true
AuthSettings__Admins_Require_2FA=true
AuthSettings__API_Key_HMAC_Secret=replace_with_a_unique_random_api_key_hmac_secret_before_running
# Pastes
PasteSettings__MaxTitleLength=500
PasteSettings__MaxPasteSizeInBytes=1048576
PasteSettings__EnablePasteCompression=true
PasteSettings__RequiresVerification=true
PasteSettings__View_HMAC_Secret=replace_with_a_unique_random_view_hmac_secret_before_running
# Compose passes this value to both services. No separate frontend key is needed.
PasteSettings__View_Internal_API_Key=replace_with_a_unique_random_internal_api_key_before_running
+1 -1
View File
@@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 24
cache: npm
cache-dependency-path: SharpbinV3.Client/package-lock.json
- run: npm ci
+3 -1
View File
@@ -325,4 +325,6 @@ Data
!SharpbinV3.Server/Data
.idea
**/.env
**/.env
backend.env
frontend.env
+53
View File
@@ -1,3 +1,56 @@
## [3.1.0](https://github.com/whoswhip/Sharpbin/compare/v3.0.5...v3.1.0) (2026-10-18)
### Bug Fixes
* add docker entrypoint sccript ([045a193](https://github.com/whoswhip/Sharpbin/commit/045a1934d80277b75b34d7566ea283c57a7b1e83))
* add tooltip to comment timestamp for better context ([c98e5e5](https://github.com/whoswhip/Sharpbin/commit/c98e5e53b02002ac0328947cdbabddaa60ebe877))
* allow null display name when saving display name ([20473da](https://github.com/whoswhip/Sharpbin/commit/20473da0bacc891354ef75cd05b4fdb3443ae629))
* always underline users in comments ([e239bf2](https://github.com/whoswhip/Sharpbin/commit/e239bf2ae5a4ca0f93cfc197d9658df459b87d10))
* compact paste smaller; better edited display ([e8cd93e](https://github.com/whoswhip/Sharpbin/commit/e8cd93e7bdfc47e0c105935182c7062fd191cb57))
* disable but show buttons for author or anon users ([77f6623](https://github.com/whoswhip/Sharpbin/commit/77f6623fcf6b9b50e26ce533cee7b83c26836051))
* disable styles on comment reactions ([23f0c92](https://github.com/whoswhip/Sharpbin/commit/23f0c92aed9bd8235ad1cc6b62aa3c9bf8674370))
* disabled:cursor-not-allowed on like buttons ([95a5c18](https://github.com/whoswhip/Sharpbin/commit/95a5c18dc57ad33701bbd6d9f5cfcf6a1cda6f49))
* enforce 2fa only on certain update actions ([a55268a](https://github.com/whoswhip/Sharpbin/commit/a55268afdc171d3d7f074ee008be3434e14c0482))
* enhance user update permissions and authentication checks ([6c810b0](https://github.com/whoswhip/Sharpbin/commit/6c810b07b738ca2cb0cfe87c264e26395254024b))
* handle username conflict during user creation ([f5a7aab](https://github.com/whoswhip/Sharpbin/commit/f5a7aabf42a67969baf6e307b3178e89c75a4716))
* improve paste description ([60796a8](https://github.com/whoswhip/Sharpbin/commit/60796a85fb3f287cc88d42dda7f9bc446d0d5f97))
* include '.' before extension on paste download ([ee6a6d5](https://github.com/whoswhip/Sharpbin/commit/ee6a6d5e6d3f4d5ef2fb2c8f6032e695b228fcf9))
* lower vulnerabilities + harden docker setup ([d16f1f8](https://github.com/whoswhip/Sharpbin/commit/d16f1f872fa34de460f9ee8903b4eefbe780c041))
* make cursor-not-allowed !important ([9916930](https://github.com/whoswhip/Sharpbin/commit/99169305c7b496eef51cfb5493cd3c8548f366e7))
* multiple vulnerabilities ([6a7b865](https://github.com/whoswhip/Sharpbin/commit/6a7b8653dc154366c85de32dccf242a071eebdf0))
* normalize canonical URL to prevent duplicate content issues ([ad693b2](https://github.com/whoswhip/Sharpbin/commit/ad693b28ea701554fceede1f8e30e7990240281c))
* normalize cononical ([d45f253](https://github.com/whoswhip/Sharpbin/commit/d45f253c000e834db584fed89ddb541c09f466c7))
* only show report button if logged in ([40c6ac6](https://github.com/whoswhip/Sharpbin/commit/40c6ac663f95c40a154dc56598bdfe6e59f38703))
* prevent admins and moderators from being reported ([f2c67ae](https://github.com/whoswhip/Sharpbin/commit/f2c67ae3677658efaf84811271f62c5043797460))
* prevent authors from reacting to their pas6te ([3da7f99](https://github.com/whoswhip/Sharpbin/commit/3da7f99feba4aaaa02a6e9f0c7771a548e6530c3))
* remove recipient information from warning log when email settings are incomplete ([b65d3f8](https://github.com/whoswhip/Sharpbin/commit/b65d3f8726f77f2b7260e97ba439bfea4e2ad908))
* remove trailing '.' in filename ([b0e9f51](https://github.com/whoswhip/Sharpbin/commit/b0e9f5104c92a3cb6a8965d23460c86a64595d12))
* show uncompressed size in stats ([61efbf8](https://github.com/whoswhip/Sharpbin/commit/61efbf8b0415fe159b5e777f737ee4e8b25beb02))
* sizeStored -> StoredSize in typescript paste type ([6c65a52](https://github.com/whoswhip/Sharpbin/commit/6c65a52ee06c266eeeb5519e779eb49f73be33b7))
* update robots.txt to specify allowed and disallowed paths for web crawlers ([ea634fd](https://github.com/whoswhip/Sharpbin/commit/ea634fd85135d2996e96f6a48ce2fbccbb75b7e2))
* update TypeScript configuration to extend from $app/tsconfig and adjust include/exclude paths ([f2559ea](https://github.com/whoswhip/Sharpbin/commit/f2559eaad0ac79ac2ee18f3b9388ce62b11b5543))
* use #lib instead of $lib ([8d06020](https://github.com/whoswhip/Sharpbin/commit/8d060204c890018f49147e681f94a6737ac1c4b1)), closes [#lib](https://github.com/whoswhip/Sharpbin/issues/lib)
* use node env instead of sveltekit env ([0e3a6d9](https://github.com/whoswhip/Sharpbin/commit/0e3a6d97e395c605d419c2464c3b7fccbcdd5c6f))
### Features
* add /[@username](https://github.com/username) redirect to /user/username ([70e637b](https://github.com/whoswhip/Sharpbin/commit/70e637b281ae060e40ceb6e312591276d1c68540))
* add bot detection to skip recording views for known bots ([41d4411](https://github.com/whoswhip/Sharpbin/commit/41d441135cdef6c22df34a512507ef7032009db9))
* add sub tab to the settings tab ([e20a620](https://github.com/whoswhip/Sharpbin/commit/e20a6200dd3c1f0dfe26645c625cac448dc50d76))
* allow staff members to see user's unlisted pastes; show dislikes in the paste lists ([6ed2974](https://github.com/whoswhip/Sharpbin/commit/6ed2974e42df9d10da755af6897b4eea4ee6d34a))
* **auth:** enhance token management and synchronization with user data ([2864c81](https://github.com/whoswhip/Sharpbin/commit/2864c81f83ca49032a803f8ca2ccad19a1f8d9fe))
* comments & paste/comment reactions; renames/refactors ([63b77be](https://github.com/whoswhip/Sharpbin/commit/63b77bece9b71d547d15403257da44e8597db97b))
* **comments:** implement delete comment functionality with confirmation modal ([95ca811](https://github.com/whoswhip/Sharpbin/commit/95ca811d4295759b3fc161eff9ba81c7499be254))
* **comments:** implement recursive comment deletion in HardDeleteComment method ([8d3caf5](https://github.com/whoswhip/Sharpbin/commit/8d3caf5375a8065281b917b1c24970580799a059))
* enhance SEO for home, recent, and paste pages ([edffd54](https://github.com/whoswhip/Sharpbin/commit/edffd5490fae8274293982ded81c7971b614fd28))
* improve rate limit partition keys + less strict limits ([6cadc0b](https://github.com/whoswhip/Sharpbin/commit/6cadc0b74d3b5cb340347b1fc8dbaf8f06318e5b))
* **modal:** refactor modal types and integrate security action requirements ([f82d314](https://github.com/whoswhip/Sharpbin/commit/f82d314d80dcd8e70f197c254bb4e7ba2fee67f0))
* password resets ([d4976ac](https://github.com/whoswhip/Sharpbin/commit/d4976ac9aac41cb7ad23070480862bf2cec89095))
## [3.0.5](https://github.com/whoswhip/Sharpbin/compare/v3.0.4...v3.0.5) (2026-03-31)
+44 -10
View File
@@ -26,15 +26,45 @@ The easiest way to run SharpbinV3 is using Docker Compose.
git clone https://github.com/whoswhip/Sharpbin.git
```
3. Run the following command in the root directory:
3. In the repository root, copy `.env.example` to `.env`.
4. Replace the secret placeholders and configure your domain and Turnstile keys. Set `ORIGIN` to the public frontend URL, including the scheme. For local Docker testing, use `ORIGIN=http://localhost:5173`, `Domain=localhost:5173`, `Https=false`, and `AllowedCorsOrigins__0=http://localhost:5173`.
5. Run the following command in the root directory:
```bash
docker-compose up -d
docker compose up -d --build
```
### Configuration
You can configure Sharpbin using environment variables or `appsettings.json`. When using Docker Compose, these can be set in the `docker-compose.yml` file.
Configure Sharpbin in the root `.env` file when using Docker Compose. The backend loads this file as environment variables. Compose passes only the backend URL, public origin, and shared view-recording key to the frontend.
The backend image includes `appsettings.json` with application defaults. Environment variables have priority, so you do not need to edit or mount that file for normal setup. Additional backend settings, including `EmailSettings__Host` and other SMTP settings, can be added to `.env` using their existing names.
Compose defaults the database to `/app/data/sharpbin.db`, Data Protection keys to `/app/data/keys`, and `VITE_API_URL` to `http://backend:8080`. To override them, add `ConnectionStrings__DefaultConnection`, `DATA_PROTECTION_KEY_PATH`, or `VITE_API_URL` to `.env`. Keep database and key paths under `/app/data` to use the existing persistent volume.
The example secrets are placeholders, not secure defaults. Generate a separate secret for JWT signing, API-key hashing, and view hashing, plus one shared internal API key. This command generates a 64-character random hex value; run it once for each secret:
```bash
docker run --rm node:24-alpine node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"
```
or use openSSL:
```bash
openssl rand -hex 32
```
Set the shared key once as `PasteSettings__View_Internal_API_Key`. Compose supplies it to the frontend as `VIEW_INTERNAL_API_KEY`. Keep generated secrets across restarts and updates. Changing the API-key HMAC secret invalidates existing API keys.
#### Migrating an Existing Installation
1. Copy the values from `backend.env` into the root `.env` file. If `.env` already exists, merge the settings without replacing existing values blindly.
2. Copy `ORIGIN` from `frontend.env`. If it was unset, use your public frontend URL, including the scheme.
3. Keep `PasteSettings__View_Internal_API_Key` set to the existing shared key. The separate `VIEW_INTERNAL_API_KEY` entry is no longer needed for Compose.
4. Move any custom `appsettings.json` values into `.env` using `__` for nested settings. For array settings, use numbered entries such as `AllowedCorsOrigins__0`. If you need to retain a custom JSON file, add a read-only mount for it in `compose.override.yaml`.
5. Run `docker compose up -d --build`. The old `backend.env` and `frontend.env` files are no longer read by Compose.
Keep the existing database volume, Data Protection keys, and secret values. Do not regenerate secrets during this migration.
> When configuring via `appsettings.json` instead of for example `ConnectionStrings__DefaultConnection` it would be:
@@ -47,9 +77,10 @@ You can configure Sharpbin using environment variables or `appsettings.json`. Wh
#### Backend (SharpbinV3.Server)
- `Domain`: The domain your instance of Sharpbin will be hosted at (e.g., example.com)
- `Https`: Whether or not your instance is behind https. Used when sendings emails.
- `Https`: Whether the public instance uses HTTPS. Used when generating email links; this does not enable TLS on the server.
- `AllowedCorsOrigins__0`: An allowed browser origin for the backend API (e.g., `https://example.com`). Use numbered entries for additional origins.
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=/app/data/sharpbin.db`).
- `JwtSettings__Secret`: A secure string used for signing JWT tokens.
- `JwtSettings__Secret`: A random secret of 32-128 characters used for signing JWT tokens.
- `AuthSettings__CF_Turnstile_SecretKey`: Your Cloudflare Turnstile secret key.
- `AuthSettings__CF_Turnstile_SiteKey`: Your Cloudflare Turnstile site key.
- `AuthSettings__Registration_Enabled`:**true**: Enables/disables registration.
@@ -60,14 +91,17 @@ You can configure Sharpbin using environment variables or `appsettings.json`. Wh
- `PasteSettings__MaxPasteSizeInBytes`:**1_048_576** (1MB): Max Paste Size set in bytes.
- `PasteSettings__EnablePasteCompression`:**true**: Enables/Disables server-side paste compression.
- `PasteSettings__RequiresVerification`:**true**: Enables/Disables CAPTCHA verification when creating pastes.
- `PasteSettings__View_HMAC_Secret`: Required to securely hash viewer identifiers
- `PasteSettings__View_Internal_API_Key`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `PasteSettings__View_HMAC_Secret`: A required random secret of 32–128 characters used to hash viewer identifiers.
- `PasteSettings__View_Internal_API_Key`: A shared key of 32–128 characters used to authorize view recording. Compose passes it to both services.
#### Frontend (SharpbinV3.Client)
- `VITE_API_URL`: The URL of the backend API (e.g., `http://localhost:8080`).
- `VITE_ALLOWED_HOSTS`: A comma separated list of allowed hosts (e.g., `localhost,sharpbin.cc`)
- `VIEW_INTERNAL_API_KEY`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `VITE_API_URL`: The backend URL reachable from the frontend server. Defaults to `http://localhost:5050` when running directly and `http://backend:8080` in Compose. Browser requests use the frontend's `/api` proxy.
- `ORIGIN`: The public frontend URL, including its scheme (e.g., `https://example.com`). Used by the production Node server; see [SvelteKit's Node adapter documentation](https://svelte.dev/docs/kit/adapter-node#ORIGIN-PROTOCOL_HEADER-HOST_HEADER-and-PORT_HEADER).
- `VITE_ALLOWED_HOSTS`: A comma-separated list used only by Vite dev/preview (e.g., `localhost,sharpbin.cc`). Export it in the shell before starting Vite; the config reads `process.env` directly. It does not configure production host restrictions.
- `VIEW_INTERNAL_API_KEY`: The production frontend's shared view-recording key. Compose sets it from `PasteSettings__View_Internal_API_Key`; do not duplicate it in the root `.env`. When running the frontend directly, set it yourself or use the existing `View_HMAC_Internal_API_Key` fallback.
When `NODE_ENV=development`, the frontend uses a fixed development-only internal key matching the backend's checked-in development configuration and ignores both environment key names. See the [client README](SharpbinV3.Client/README.md) for development and standalone production setup.
The frontend will be accessible at http://localhost:5173.
+2 -2
View File
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM node:20-alpine as build
FROM node:24-alpine as build
ARG GIT_COMMIT_HASH
ENV GIT_COMMIT_HASH=${GIT_COMMIT_HASH}
WORKDIR /app
@@ -8,7 +8,7 @@ RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine as runner
FROM node:24-alpine as runner
WORKDIR /app
ENV NODE_ENV=production
ENV HOST=0.0.0.0
+25 -5
View File
@@ -6,7 +6,7 @@ This is the SvelteKit frontend for SharpbinV3.
### Prerequisites
- Node.js (v20 or newer recommended)
- Node.js 24
- npm
### Installation
@@ -19,11 +19,12 @@ npm install
### Environment Configuration
The frontend requires an environment variable to point to the backend API. Create a `.env` file in this directory or set the variable in your environment:
The frontend defaults to the backend at `http://localhost:5050`. SvelteKit loads `.env` files during development, but `vite.config.ts` reads shell environment variables directly for its proxy and allowed hosts:
- `VITE_API_URL`: The URL of the backend API (e.g., `http://localhost:8080`).
- `VITE_ALLOWED_HOSTS`: A comma separated list of allowed hosts (e.g., `localhost,sharpbin.whoswhip.dev`)
- `VIEW_INTERNAL_API_KEY`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `VITE_API_URL`: The backend URL reachable from the frontend server. Export this in the shell when changing the development backend URL so the Vite proxy and server-side requests use the same value.
- `VITE_ALLOWED_HOSTS`: A comma-separated list of hosts for Vite dev/preview. Export this in the shell before starting Vite. It does not configure the production Node server.
In development, the frontend uses a fixed internal view-recording key matching `appsettings.Development.json`. It ignores `VIEW_INTERNAL_API_KEY` and `View_HMAC_Internal_API_Key` while `NODE_ENV=development`.
### Running in Development
@@ -35,6 +36,25 @@ npm run dev
The frontend will be available at http://localhost:5173.
### Running in Production
Docker Compose reads the root `.env` file and runs the built Node server on port 5173. Configure these values there:
- `VITE_API_URL`: Backend URL. Defaults to `http://backend:8080` in Compose.
- `ORIGIN`: Public frontend URL, such as `https://example.com` or `http://localhost:5173` for local Docker testing.
- `PasteSettings__View_Internal_API_Key`: Shared view-recording key. Compose passes it to the frontend as `VIEW_INTERNAL_API_KEY`, so you only set it once.
For a standalone Node deployment, set `VITE_API_URL`, `ORIGIN`, and `VIEW_INTERNAL_API_KEY` in the client's own `.env` file. The key must match the backend's `PasteSettings__View_Internal_API_Key`. The frontend still supports `View_HMAC_Internal_API_Key` as a fallback; it does not read the backend setting name directly.
The standalone server does not load `.env` automatically. Build the frontend, then load your environment file explicitly:
```bash
npm run build
node --env-file=.env build
```
Set `PORT=5173` in that file to use the same port as Docker; the Node adapter otherwise defaults to port 3000. See the [Node adapter documentation](https://svelte.dev/docs/kit/adapter-node#Environment-variables) for runtime configuration.
## Script Reference
- `npm run dev`: Start the Vite development server.
+1 -3
View File
@@ -6,7 +6,6 @@ import svelte from 'eslint-plugin-svelte';
import { defineConfig } from 'eslint/config';
import globals from 'globals';
import ts from 'typescript-eslint';
import svelteConfig from './svelte.config.js';
const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));
@@ -33,8 +32,7 @@ export default defineConfig(
parserOptions: {
projectService: true,
extraFileExtensions: ['.svelte'],
parser: ts.parser,
svelteConfig
parser: ts.parser
}
}
}
+456 -941
View File
File diff suppressed because it is too large Load Diff
+13 -8
View File
@@ -1,7 +1,7 @@
{
"name": "sharpbinv3.client",
"private": true,
"version": "3.0.5",
"version": "3.1.0",
"type": "module",
"scripts": {
"dev": "vite dev",
@@ -17,8 +17,8 @@
"devDependencies": {
"@eslint/compat": "^1.4.0",
"@eslint/js": "^9.39.1",
"@sveltejs/adapter-auto": "^7.0.0",
"@sveltejs/kit": "^2.60.1",
"@sveltejs/adapter-auto": "^8.0.0",
"@sveltejs/kit": "^3.0.1",
"@sveltejs/vite-plugin-svelte": "^7.1.2",
"@tailwindcss/vite": "^4.3.1",
"@types/better-sqlite3": "^7.6.13",
@@ -26,6 +26,7 @@
"@types/node": "^22",
"@types/papaparse": "^5.5.2",
"@types/qrcode": "^1.5.6",
"@types/sharp": "^0.31.1",
"conventional-changelog": "^7.1.1",
"conventional-changelog-angular": "^8.1.0",
"eslint": "^9.39.1",
@@ -39,18 +40,22 @@
"svelte-check": "^4.3.4",
"tailwind-scrollbar": "^4.0.2",
"tailwindcss": "^4.1.17",
"typescript": "^5.9.3",
"typescript-eslint": "^8.48.1",
"typescript": "^6.0.3",
"typescript-eslint": "^8.71.2",
"vite": "^8.0.16"
},
"imports": {
"#lib": "./src/lib/index.ts",
"#lib/*": "./src/lib/*"
},
"dependencies": {
"@fontsource/inter": "^5.2.8",
"@fontsource/jetbrains-mono": "^5.2.8",
"@lucide/svelte": "^0.562.0",
"@resvg/resvg-js": "^2.6.2",
"@sveltejs/adapter-node": "^5.4.0",
"@sveltejs/adapter-node": "^6.0.0",
"better-sqlite3": "^12.8.0",
"dompurify": "^3.4.11",
"dompurify": "^3.4.16",
"hash-wasm": "^4.12.0",
"highlight.js": "^11.8.0",
"jsdom": "^27.4.0",
@@ -59,6 +64,6 @@
"qrcode": "^1.5.4",
"satori": "^0.26.0",
"satori-html": "^0.3.2",
"sharp": "^0.34.5"
"sharp": "^0.35.5"
}
}
@@ -1,10 +1,10 @@
<script lang="ts">
import QRCode from 'qrcode';
import { getRefreshToken, getToken, setTokens } from '$lib/utils/auth';
import { parseTotpEnabled } from '$lib/utils/totp';
import { getRefreshToken, getToken, setTokens } from '#lib/utils/auth';
import { parseTotpEnabled } from '#lib/utils/totp';
import { tick } from 'svelte';
import { extractError } from '$lib/utils/misc';
import type { ModalItem, ModalMode } from '$lib/types/modal';
import { extractError } from '#lib/utils/misc';
import type { ModalItem, ModalMode } from '#lib/types/modal';
interface Props {
show?: boolean;
@@ -1,6 +1,6 @@
<script lang="ts">
import Modal from '$lib/components/Modal.svelte';
import { cancelModal, confirmModal, modal } from '$lib/stores/modal';
import Modal from '#lib/components/Modal.svelte';
import { cancelModal, confirmModal, modal } from '#lib/stores/modal';
let state = $derived($modal);
</script>
@@ -1,9 +1,9 @@
<script lang="ts">
import { user } from '$lib/stores/user';
import { user } from '#lib/stores/user';
import { resolve } from '$app/paths';
import { page } from '$app/state';
import { clearTokens, hasRole } from '$lib/utils/auth';
import logo from '$lib/assets/favicon.svg';
import { clearTokens, hasRole } from '#lib/utils/auth';
import logo from '#lib/assets/favicon.svg';
import type { PageData } from '../../routes/$types';
import { slide } from 'svelte/transition';
import { Menu, X } from '@lucide/svelte';
@@ -1,5 +1,5 @@
<script lang="ts">
import { tooltip, dateToRelativeString, formatNumber, formatBytes } from '$lib/utils/misc';
import { tooltip, dateToRelativeString, formatNumber, formatBytes } from '#lib/utils/misc';
import { resolve } from '$app/paths';
import {
Eye,
@@ -15,8 +15,8 @@
HatGlasses,
ThumbsUp
} from '@lucide/svelte';
import { syntaxes } from '$lib/consts';
import type { Paste } from '$lib/types/paste';
import { syntaxes } from '#lib/consts';
import type { Paste } from '#lib/types/paste';
interface Props {
paste: Paste;
@@ -34,7 +34,7 @@
{#if compact}
<a
href={resolve(`/${paste.id}`)}
href={resolve(`/[id]`, { id: paste.id })}
class="flex flex-col gap-1 rounded border border-neutral-700 bg-neutral-800 px-4 py-3 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
>
<div class="flex w-full flex-row justify-between">
@@ -119,7 +119,7 @@
</a>
{:else}
<a
href={resolve(`/${paste.id}`)}
href={resolve(`/[id]`, { id: paste.id })}
class="flex flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
>
<span
@@ -1,14 +1,14 @@
<script lang="ts">
import type { CommentReaction, CommentTreeNode } from '$lib/types/comment';
import { dateToRelativeString, tooltip } from '$lib/utils/misc';
import { parseCommentMarkdown } from '$lib/utils/markdown';
import { escapeHtml } from '$lib/utils/html';
import { user } from '$lib/stores/user';
import PasteCommentItem from '$lib/components/PasteCommentItem.svelte';
import type { CommentReaction, CommentTreeNode } from '#lib/types/comment';
import { dateToRelativeString, tooltip } from '#lib/utils/misc';
import { parseCommentMarkdown } from '#lib/utils/markdown';
import { escapeHtml } from '#lib/utils/html';
import { user } from '#lib/stores/user';
import PasteCommentItem from '#lib/components/PasteCommentItem.svelte';
import { ThumbsUp, ThumbsDown, Trash2, Shredder, Reply, Quote } from '@lucide/svelte';
import { resolve } from '$app/paths';
import RichTextEditor from './RichTextEditor.svelte';
import { hasRole, roles } from '$lib/utils/auth';
import { hasRole, roles } from '#lib/utils/auth';
interface Props {
node: CommentTreeNode;
@@ -101,7 +101,7 @@
<span class="text-red-500">BANNED</span>
{/if}
<a
href={resolve(`/user/${node.author?.username}`)}
href={resolve(`/user/[username]`, { username: node.author?.username})}
class="flex items-center gap-2 underline"
>
<span
@@ -1,17 +1,17 @@
<script lang="ts">
import { onMount } from 'svelte';
import { getToken } from '$lib/utils/auth';
import { user } from '$lib/stores/user';
import { getToken } from '#lib/utils/auth';
import { user } from '#lib/stores/user';
import type {
CommentReaction,
CommentReactionResult,
PasteComment,
CommentTreeNode
} from '$lib/types/comment';
import PasteCommentItem from '$lib/components/PasteCommentItem.svelte';
} from '#lib/types/comment';
import PasteCommentItem from '#lib/components/PasteCommentItem.svelte';
import { SvelteMap } from 'svelte/reactivity';
import RichTextEditor from './RichTextEditor.svelte';
import { openModal } from '$lib/stores/modal';
import { openModal } from '#lib/stores/modal';
import { RefreshCw } from '@lucide/svelte';
interface Props {
@@ -237,15 +237,13 @@
}
</script>
<section id="comments-section" class="mt-6 rounded border border-neutral-700 bg-neutral-900 p-4">
<section
id="comments-section"
class="mt-4 w-[95%] max-w-7xl rounded border-2 border-neutral-800 bg-neutral-900 p-4"
>
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
<div class="flex items-center gap-2">
<h2 class="text-lg font-semibold text-neutral-100">Comments</h2>
<span
class="rounded border border-neutral-700 bg-neutral-800 px-2 py-0.5 text-xs text-neutral-300"
>
{comments.length}
</span>
<h2 class="text-lg font-semibold text-neutral-100">{comments.length} Comments</h2>
</div>
<button
type="button"
@@ -1,6 +1,6 @@
<script lang="ts">
import { Bold, Italic, CodeXml, Quote, Send, Eye, Pencil } from '@lucide/svelte';
import { parseCommentMarkdown } from '$lib/utils/markdown';
import { parseCommentMarkdown } from '#lib/utils/markdown';
interface Props {
class?: string;
+1 -1
View File
@@ -1 +1 @@
// place files you want to import through the `$lib` alias in this folder.
// place files you want to import through the `#lib` alias in this folder.
+1 -1
View File
@@ -1,4 +1,4 @@
import { env } from '$env/dynamic/private';
import { env } from 'node:process';
export const apiUrl = env.VITE_API_URL ?? 'http://localhost:5050';
export const viewInternalApiKey =
+1 -1
View File
@@ -1,4 +1,4 @@
import { apiUrl } from '$lib/server/api';
import { apiUrl } from '#lib/server/api';
const methodsWithoutBody = new Set(['GET', 'HEAD']);
+1 -1
View File
@@ -1,5 +1,5 @@
import { writable } from 'svelte/store';
import type { ModalOpenOptions, ModalState } from '$lib/types/modal';
import type { ModalOpenOptions, ModalState } from '#lib/types/modal';
const initialState: ModalState = {
show: false,
+1 -1
View File
@@ -1,6 +1,6 @@
import { writable } from 'svelte/store';
import { browser } from '$app/environment';
import type { AuthUser } from '$lib/types/user';
import type { AuthUser } from '#lib/types/user';
let initial: AuthUser | null = null;
@@ -0,0 +1,9 @@
import { argon2id } from 'hash-wasm';
self.onmessage = async (event: MessageEvent<Parameters<typeof argon2id>[0]>) => {
try {
self.postMessage(await argon2id(event.data));
} catch {
self.postMessage(null);
}
};
+2 -2
View File
@@ -1,7 +1,7 @@
import { browser } from '$app/environment';
import type { Cookies } from '@sveltejs/kit';
import { user } from '$lib/stores/user';
import type { JWTUser } from '$lib/types/user';
import { user } from '#lib/stores/user';
import type { JWTUser } from '#lib/types/user';
export const roles = {
User: 1,
+128 -19
View File
@@ -1,5 +1,3 @@
import { argon2id } from 'hash-wasm';
const BASE64_CHUNK_SIZE = 0x8000;
const SALT_LENGTH = 16;
const IV_LENGTH = 12;
@@ -9,8 +7,58 @@ const ARGON2_PARALLELISM = 1;
const ARGON2_HASH_LENGTH = 32;
const AES_KEY_LENGTH = 256;
const ENCRYPTION_AAD = 'enc-v4';
const ENCRYPTED_DATA_OVERHEAD = 60;
const ENCRYPTED_METADATA_OVERHEAD = 150;
const ENCRYPTED_DATA_OVERHEAD = SALT_LENGTH + IV_LENGTH + 16;
const MAX_ENVELOPE_LENGTH = 16 * 1024 * 1024;
const ENCRYPTION_HEADER = {
version: 5,
kdf: 'Argon2id',
memorySize: ARGON2_MEMORY_SIZE,
iterations: ARGON2_ITERATIONS,
parallelism: ARGON2_PARALLELISM,
algorithm: 'AES-GCM',
saltLength: SALT_LENGTH,
ivLength: IV_LENGTH
};
let derivingKey = false;
async function argon2id(
options: Parameters<typeof import('hash-wasm').argon2id>[0]
): Promise<Uint8Array<ArrayBuffer>> {
if (derivingKey) throw new Error('Another encryption operation is already running.');
derivingKey = true;
try {
return await new Promise((resolve, reject) => {
const worker = new Worker(new URL('./argon2.worker.ts', import.meta.url), { type: 'module' });
const finish = () => {
clearTimeout(timeout);
worker.terminate();
};
const timeout = setTimeout(() => {
finish();
reject(new Error('Key derivation timed out.'));
}, 60_000);
worker.onmessage = (event: MessageEvent<Uint8Array | null>) => {
finish();
if (event.data instanceof Uint8Array && event.data.length === ARGON2_HASH_LENGTH) {
resolve(new Uint8Array(event.data));
} else reject(new Error('Key derivation failed. The device may lack memory.'));
};
worker.onerror = (event) => {
event.preventDefault();
finish();
reject(new Error('Unable to run the encryption worker.'));
};
try {
worker.postMessage(options);
} catch (error) {
finish();
reject(error);
}
});
} finally {
derivingKey = false;
}
}
function toBase64(bytes: Uint8Array): string {
let binary = '';
@@ -29,7 +77,21 @@ function fromBase64(data: string): Uint8Array {
return bytes;
}
export function encodePasswordFragment(password: string): string {
return `u1.${toBase64(new TextEncoder().encode(password))}`;
}
export function decodePasswordFragment(fragment: string): string {
return fragment.startsWith('u1.')
? new TextDecoder('utf-8', { fatal: true }).decode(fromBase64(fragment.slice(3)))
: atob(fragment);
}
export async function encryptAES(content: string, password: string): Promise<string> {
if (!password) throw new Error('Password required for encryption.');
if (estimateEncryptedSize(content) > MAX_ENVELOPE_LENGTH) {
throw new Error('Encrypted paste exceeds the supported size limit.');
}
const enc = new TextEncoder();
const salt = window.crypto.getRandomValues(new Uint8Array(SALT_LENGTH));
@@ -56,7 +118,7 @@ export async function encryptAES(content: string, password: string): Promise<str
{
name: 'AES-GCM',
iv,
additionalData: enc.encode(ENCRYPTION_AAD)
additionalData: enc.encode(JSON.stringify(ENCRYPTION_HEADER))
},
key,
enc.encode(content)
@@ -68,14 +130,7 @@ export async function encryptAES(content: string, password: string): Promise<str
combined.set(new Uint8Array(encryptedContent), salt.byteLength + iv.byteLength);
return JSON.stringify({
version: 4,
kdf: 'Argon2id',
memorySize: ARGON2_MEMORY_SIZE,
iterations: ARGON2_ITERATIONS,
parallelism: ARGON2_PARALLELISM,
algorithm: 'AES-GCM',
saltLength: salt.byteLength,
ivLength: iv.byteLength,
...ENCRYPTION_HEADER,
data: toBase64(combined)
});
}
@@ -84,17 +139,58 @@ export function estimateEncryptedSize(content: string): number {
const rawSize = new TextEncoder().encode(content).length;
const combinedSize = rawSize + ENCRYPTED_DATA_OVERHEAD;
const b64Size = Math.ceil(combinedSize / 3) * 4;
return b64Size + ENCRYPTED_METADATA_OVERHEAD;
return b64Size + JSON.stringify({ ...ENCRYPTION_HEADER, data: '' }).length;
}
export async function decryptAES(result: string, password: string): Promise<string | null> {
try {
const enc = new TextEncoder();
if (result.length > MAX_ENVELOPE_LENGTH) {
throw new Error('Encrypted paste exceeds the supported size limit.');
}
const parsed = JSON.parse(result);
if (!parsed || typeof parsed !== 'object' || parsed.algorithm !== 'AES-GCM') {
throw new Error('Unsupported or malformed encrypted paste.');
}
const legacyPBKDF2 =
parsed.version === 1 &&
parsed.kdf === 'PBKDF2' &&
parsed.iterations === 100000 &&
parsed.hash === 'SHA-256' &&
(parsed.saltLength === undefined || parsed.saltLength === SALT_LENGTH) &&
(parsed.ivLength === undefined || parsed.ivLength === IV_LENGTH);
const legacyArgon2 =
parsed.version === 4 && parsed.memorySize === 65536 && parsed.saltLength === 32;
const currentArgon2 =
(parsed.version === 4 || parsed.version === 5) &&
parsed.memorySize === ARGON2_MEMORY_SIZE &&
parsed.saltLength === SALT_LENGTH;
if (
!legacyPBKDF2 &&
!(
parsed.kdf === 'Argon2id' &&
parsed.iterations === ARGON2_ITERATIONS &&
parsed.parallelism === ARGON2_PARALLELISM &&
parsed.ivLength === IV_LENGTH &&
(legacyArgon2 || currentArgon2)
)
)
throw new Error('Unsupported encryption profile.');
if (
typeof parsed.data !== 'string' ||
!parsed.data.length ||
parsed.data.length % 4 !== 0 ||
!/^[A-Za-z0-9+/]*={0,2}$/.test(parsed.data)
) {
throw new Error('Malformed encrypted-paste encoding.');
}
const combined = fromBase64(parsed.data);
const saltLength = parsed.saltLength || SALT_LENGTH;
const ivLength = parsed.ivLength || IV_LENGTH;
const saltLength = parsed.saltLength ?? SALT_LENGTH;
const ivLength = parsed.ivLength ?? IV_LENGTH;
if (combined.length < saltLength + ivLength + 16) {
throw new Error('Encrypted paste is truncated.');
}
const salt = combined.slice(0, saltLength);
const iv = combined.slice(saltLength, saltLength + ivLength);
const data = combined.slice(saltLength + ivLength);
@@ -146,14 +242,27 @@ export async function decryptAES(result: string, password: string): Promise<stri
{
name: 'AES-GCM',
iv,
additionalData: enc.encode(ENCRYPTION_AAD)
additionalData: enc.encode(
parsed.version === 5
? JSON.stringify(ENCRYPTION_HEADER)
: currentArgon2
? ENCRYPTION_AAD
: ''
)
},
key,
data
);
return new TextDecoder().decode(decryptedContent);
} catch {
return null;
} catch (error) {
if (error instanceof DOMException && error.name === 'OperationError') return null;
if (
error instanceof SyntaxError ||
(error instanceof DOMException && error.name === 'InvalidCharacterError')
) {
throw new Error('Malformed encrypted paste.');
}
throw error;
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { marked } from 'marked';
import createDOMPurify from 'dompurify';
import type { WindowLike } from 'dompurify';
import { trustedDomains } from '$lib/consts';
import { trustedDomains } from '#lib/consts';
import { escapeHtml } from './html';
export const externalMediaWarningStorageKey = 'sharpbin:ignore-external-media-warning';
+1 -1
View File
@@ -1,4 +1,4 @@
import { syntaxes } from '$lib/consts';
import { syntaxes } from '#lib/consts';
/**
* @param bytes Bytes to format.
+7 -7
View File
@@ -1,13 +1,13 @@
<script lang="ts">
import { onMount } from 'svelte';
import './layout.css';
import favicon from '$lib/assets/favicon.svg';
import Navbar from '$lib/components/Navbar.svelte';
import Footer from '$lib/components/Footer.svelte';
import ModalHost from '$lib/components/ModalHost.svelte';
import { user } from '$lib/stores/user';
import { startTokenRefreshInterval, getToken, refreshTokenIfNeeded } from '$lib/utils/auth';
import { parseTotpEnabled } from '$lib/utils/totp';
import favicon from '#lib/assets/favicon.svg';
import Navbar from '#lib/components/Navbar.svelte';
import Footer from '#lib/components/Footer.svelte';
import ModalHost from '#lib/components/ModalHost.svelte';
import { user } from '#lib/stores/user';
import { startTokenRefreshInterval, getToken, refreshTokenIfNeeded } from '#lib/utils/auth';
import { parseTotpEnabled } from '#lib/utils/totp';
import { page } from '$app/state';
import type { LayoutData } from './$types';
+14 -9
View File
@@ -1,20 +1,20 @@
<script lang="ts">
import type { PageData } from './$types';
import { syntaxes, expiresOptions } from '$lib/consts';
import { user } from '$lib/stores/user';
import { getToken } from '$lib/utils/auth';
import { syntaxes, expiresOptions } from '#lib/consts';
import { user } from '#lib/stores/user';
import { getToken } from '#lib/utils/auth';
import { onMount } from 'svelte';
import { fly, fade } from 'svelte/transition';
import { encryptAES, estimateEncryptedSize } from '$lib/utils/encryption';
import { encryptAES, estimateEncryptedSize, encodePasswordFragment } from '#lib/utils/encryption';
import {
formatBytes,
formatNumber,
isBinaryData,
tooltip,
syntaxFromExtension
} from '$lib/utils/misc';
import { parseMarkdown } from '$lib/utils/markdown';
import Dropdown from '$lib/components/Dropdown.svelte';
} from '#lib/utils/misc';
import { parseMarkdown } from '#lib/utils/markdown';
import Dropdown from '#lib/components/Dropdown.svelte';
import { SvelteURLSearchParams } from 'svelte/reactivity';
import { FileUp, X, Eye, EyeClosed, Dices } from '@lucide/svelte';
@@ -162,7 +162,12 @@
let body = content;
if (selectedVisibility === 2) {
body = await encryptAES(content, password);
try {
body = await encryptAES(content, password);
} catch (cause) {
error = cause instanceof Error ? cause.message : 'Encryption failed.';
return;
}
}
if (
@@ -196,7 +201,7 @@
if (response.ok) {
const result = await response.json();
if (selectedVisibility === 2) {
const passwordBase64 = btoa(password);
const passwordBase64 = encodePasswordFragment(password);
window.location.href = `/${result.id}#${passwordBase64}`;
return;
}
@@ -1,21 +1,21 @@
import { syntaxes } from '$lib/consts';
import { apiUrl } from '$lib/server/api';
import { syntaxes } from '#lib/consts';
import { apiUrl } from '#lib/server/api';
import {
getCachedOgImage,
getCacheControlHeader,
getCacheTtlSeconds,
scheduleOgImageCachePurge,
storeCachedOgImage
} from '$lib/server/og/cache';
import OgPasteEmbed from '$lib/server/og/PasteEmbed.svelte';
import type { PasteEmbedProps } from '$lib/server/og/pasteEmbed';
import type { Paste } from '$lib/types/paste';
} from '#lib/server/og/cache';
import OgPasteEmbed from '#lib/server/og/PasteEmbed.svelte';
import type { PasteEmbedProps } from '#lib/server/og/pasteEmbed';
import type { Paste } from '#lib/types/paste';
import {
dateToRelativeString,
extractDateFromUUIDv7,
formatBytes,
formatNumber
} from '$lib/utils/misc';
} from '#lib/utils/misc';
import { Resvg } from '@resvg/resvg-js';
import { readFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
@@ -1,8 +1,8 @@
import type { PageServerLoad } from './$types';
import type { Paste } from '$lib/types/paste';
import type { PasteComment } from '$lib/types/comment';
import { getServerToken } from '$lib/utils/auth';
import { apiUrl, viewInternalApiKey } from '$lib/server/api';
import type { Paste } from '#lib/types/paste';
import type { PasteComment } from '#lib/types/comment';
import { getServerToken } from '#lib/utils/auth';
import { apiUrl, viewInternalApiKey } from '#lib/server/api';
import { error } from '@sveltejs/kit';
export const load: PageServerLoad = async ({ params, fetch, url, cookies, parent, request }) => {
+52 -30
View File
@@ -36,24 +36,24 @@
dateToRelativeString,
tooltip,
isBinaryData
} from '$lib/utils/misc';
} from '#lib/utils/misc';
import {
getIgnoreExternalMediaWarning,
parseMarkdown,
setIgnoreExternalMediaWarning
} from '$lib/utils/markdown';
import { syntaxes, expiresOptions } from '$lib/consts';
} from '#lib/utils/markdown';
import { syntaxes, expiresOptions } from '#lib/consts';
import { resolve } from '$app/paths';
import { decryptAES, encryptAES } from '$lib/utils/encryption';
import { escapeHtml } from '$lib/utils/html';
import { decryptAES, encryptAES, decodePasswordFragment } from '#lib/utils/encryption';
import { escapeHtml } from '#lib/utils/html';
import { fade } from 'svelte/transition';
import { getToken, hasRole } from '$lib/utils/auth';
import { user } from '$lib/stores/user';
import Dropdown from '$lib/components/Dropdown.svelte';
import PasteComments from '$lib/components/PasteComments.svelte';
import { openModal } from '$lib/stores/modal';
import type { Paste, PasteReaction } from '$lib/types/paste';
import HighlightWorker from '$lib/workers/highlight.worker?worker';
import { getToken, hasRole } from '#lib/utils/auth';
import { user } from '#lib/stores/user';
import Dropdown from '#lib/components/Dropdown.svelte';
import PasteComments from '#lib/components/PasteComments.svelte';
import { openModal } from '#lib/stores/modal';
import type { Paste, PasteReaction } from '#lib/types/paste';
import HighlightWorker from '#lib/workers/highlight.worker?worker';
interface Props {
data: PageData;
}
@@ -100,6 +100,9 @@
let highlightRequestId = 0;
let ignoreExternalMediaWarning = false;
let iconsOnly = $state(false);
const canonicalUrl = $derived(
data.paste ? new URL(`/${data.paste.id}`, data.url).href : undefined
);
let scrollY = $state(0);
@@ -356,8 +359,8 @@
});
editMetadata = data.paste ? { ...data.paste } : null;
}
} catch {
editError = 'An error occurred while updating.';
} catch (cause) {
editError = cause instanceof Error ? cause.message : 'An error occurred while updating.';
} finally {
editLoading = false;
editing = false;
@@ -514,8 +517,20 @@
contentRendered = false;
decryptStatus = 'Preparing decryption...';
const urlHash = window.location.hash.slice(1);
let passwordFromUrl: string | null = null;
if (urlHash) {
const passwordFromUrl = atob(urlHash);
history.replaceState(
history.state,
'',
window.location.pathname + window.location.search
);
try {
passwordFromUrl = decodePasswordFragment(urlHash);
} catch {
/* empty */
}
}
if (passwordFromUrl !== null) {
decryptStatus = 'Deriving key...';
decryptedContent = await decryptAES(data.content, passwordFromUrl);
if (decryptedContent === null) {
@@ -525,11 +540,10 @@
decryptStatus = 'Deriving key...';
decryptedContent = await decryptAES(data.content, password);
if (decryptedContent === null) {
decryptError = 'Incorrect password. Please try again.';
decryptStatus = 'Decryption failed.';
decryptError = 'Wrong password or damaged encrypted paste.';
decryptStatus = decryptError;
} else {
await renderPaste();
history.replaceState(null, '', window.location.pathname + window.location.search);
}
} else {
decryptStatus = 'Decryption canceled.';
@@ -545,8 +559,8 @@
decryptStatus = 'Deriving key...';
decryptedContent = await decryptAES(data.content, password);
if (decryptedContent === null) {
decryptError = 'Incorrect password. Please try again.';
decryptStatus = 'Decryption failed.';
decryptError = 'Wrong password or damaged encrypted paste.';
decryptStatus = decryptError;
} else {
await renderPaste();
}
@@ -557,7 +571,12 @@
decryptStatus = 'Rendering content...';
await renderPaste();
}
} catch {
} catch (cause) {
if (data?.paste?.visibility === 2) {
decryptStatus = cause instanceof Error ? cause.message : 'Unable to decrypt this paste.';
contentRendered = false;
return;
}
decryptStatus = 'Rendering content...';
await renderPaste();
}
@@ -590,14 +609,14 @@
name="robots"
content={data.paste.visibility === 0 ? 'index, follow' : 'noindex, nofollow'}
/>
<link rel="canonical" href={data.url} />
<link rel="canonical" href={canonicalUrl} />
{#if data.paste.author}
<meta name="author" content={data.paste.author.username} />
{/if}
<meta property="og:title" content={data.paste.title || 'Untitled Paste'} />
<meta property="og:description" content={pasteDescription} />
<meta property="og:type" content="article" />
<meta property="og:url" content={data.url} />
<meta property="og:url" content={canonicalUrl} />
<meta property="og:site_name" content="Sharpbin" />
{#if pasteImageUrl}
<meta property="og:image" content={pasteImageUrl} />
@@ -652,7 +671,7 @@
{#if data.paste.author}
<User class="inline-block h-4 w-4 text-neutral-400" />
<a
href={resolve(`/user/${data.paste.author.username}`)}
href={resolve(`/user/[username]`, { username: data.paste.author.username })}
class="text-neutral-400 transition-colors duration-300 hover:text-neutral-500"
>{data.paste.author.username}</a
>
@@ -899,10 +918,13 @@
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
const filename = data.paste?.title
? `${data.paste.title.slice(0, 100)}${extension ? `.${extension}` : ''}`
: `paste_${data.paste?.id}${extension ? `.${extension}` : ''}`;
a.href = url;
a.download = data.paste?.title
? `${data.paste.title.slice(0, 100)}.${extension}`
: `paste_${data.paste?.id}.${extension}`;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
@@ -932,7 +954,7 @@
</button>
<a
href={resolve(`/raw/${data.paste.id}`)}
href={resolve(`/raw/[id]`, { id: data.paste.id })}
class="flex cursor-pointer items-center rounded-md bg-neutral-700 px-2 py-0.5 text-sm hover:bg-neutral-600"
>
<File class="{iconsOnly ? '' : 'mr-1'} h-5 w-5 text-neutral-400" />
@@ -1104,14 +1126,14 @@
{@html pasteContent}
</div>
{/if}
<PasteComments pasteId={data.paste.id} initialComments={data.comments ?? []} />
{:else}
<h1 class="mb-4 text-center text-4xl font-bold">Paste not found</h1>
<h2 class="mt-2 text-center text-xl">The paste you are looking for does not exist.</h2>
{/if}
</div>
<PasteComments pasteId={data.paste.id} initialComments={data.comments ?? []} />
<style>
.hljs {
background-color: var(--color-neutral-800) !important;
@@ -1,4 +1,4 @@
import { proxyBackendRequest } from '$lib/server/proxy';
import { proxyBackendRequest } from '#lib/server/proxy';
import type { RequestHandler } from './$types';
const handle: RequestHandler = ({ params, request, url }) => {
@@ -1,6 +1,6 @@
<script lang="ts">
import { resolve } from '$app/paths';
import { extractError } from '$lib/utils/misc';
import { extractError } from '#lib/utils/misc';
import { onMount } from 'svelte';
import type { PageData } from './$types';
@@ -1,4 +1,4 @@
import { apiUrl } from '$lib/server/api';
import { apiUrl } from '#lib/server/api';
import { json } from '@sveltejs/kit';
export const GET = async () => {
@@ -1,7 +1,7 @@
<script lang="ts">
import { resolve } from '$app/paths';
import { setTokens, startTokenRefreshInterval } from '$lib/utils/auth';
import { extractError } from '$lib/utils/misc';
import { setTokens, startTokenRefreshInterval } from '#lib/utils/auth';
import { extractError } from '#lib/utils/misc';
import { onMount } from 'svelte';
import type { PageData } from './$types';
@@ -1,4 +1,4 @@
import { proxyBackendRequest } from '$lib/server/proxy';
import { proxyBackendRequest } from '#lib/server/proxy';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = ({ request, url }) => {
@@ -1,4 +1,4 @@
import { proxyBackendRequest } from '$lib/server/proxy';
import { proxyBackendRequest } from '#lib/server/proxy';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = ({ params, request, url }) => {
@@ -1,5 +1,5 @@
import type { RequestHandler } from '@sveltejs/kit';
import { apiUrl } from '$lib/server/api';
import { apiUrl } from '#lib/server/api';
export const GET: RequestHandler = async ({ params, request }) => {
const { id } = params;
@@ -1,6 +1,6 @@
import type { PageServerLoad } from './$types';
import type { Paste } from '$lib/types/paste';
import { extractError } from '$lib/utils/misc';
import type { Paste } from '#lib/types/paste';
import { extractError } from '#lib/utils/misc';
import { error } from '@sveltejs/kit';
export const load: PageServerLoad = async ({ fetch, request }) => {
@@ -1,7 +1,7 @@
<script lang="ts">
import type { PageData } from './$types';
import { onMount } from 'svelte';
import Paste from '$lib/components/Paste.svelte';
import Paste from '#lib/components/Paste.svelte';
interface Props {
data: PageData;
@@ -1,7 +1,7 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { setTokens, startTokenRefreshInterval } from '$lib/utils/auth';
import { extractError } from '$lib/utils/misc';
import { setTokens, startTokenRefreshInterval } from '#lib/utils/auth';
import { extractError } from '#lib/utils/misc';
import { Check, X, Eye, EyeClosed } from '@lucide/svelte';
import { slide, fade } from 'svelte/transition';
import { resolve } from '$app/paths';
@@ -1,8 +1,8 @@
import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { apiUrl } from '$lib/server/api';
import { getServerToken, clearServerTokens, roles, getUserFromToken } from '$lib/utils/auth';
import type { Report } from '$lib/types/report';
import { apiUrl } from '#lib/server/api';
import { getServerToken, clearServerTokens, roles, getUserFromToken } from '#lib/utils/auth';
import type { Report } from '#lib/types/report';
export const load: PageServerLoad = async ({ fetch, cookies, params, url, request }) => {
const token = getServerToken(cookies);
@@ -1,9 +1,9 @@
<script lang="ts">
import type { PageData } from './$types';
import { resolve } from '$app/paths';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '$lib/types/report';
import { tooltip } from '$lib/utils/misc';
import { getToken } from '$lib/utils/auth';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '#lib/types/report';
import { tooltip } from '#lib/utils/misc';
import { getToken } from '#lib/utils/auth';
interface Props {
data: PageData;
@@ -75,7 +75,7 @@
{#if report.reporterUsername}
<a
class="text-neutral-200 hover:text-white hover:underline"
href={resolve(`/user/${report.reporterUsername}`)}
href={resolve(`/user/[username]`, { username: report.reporterUsername})}
use:tooltip={report.reporterUUID}
>
{report.reporterDisplayName || report.reporterUsername}
@@ -89,7 +89,7 @@
Target Paste:
<a
class="text-neutral-200 hover:text-white hover:underline"
href={resolve(`/${report.pasteId}`)}
href={resolve(`/[id]`, { id: report.pasteId})}
>
{report.pasteTitle !== '' ? report.pasteTitle : report.pasteId}
</a>
@@ -101,7 +101,7 @@
{#if report.targetUsername}
<a
class="text-neutral-200 hover:text-white hover:underline"
href={resolve(`/user/${report.targetUsername}`)}
href={resolve(`/user/[username]`, { username: report.targetUsername})}
use:tooltip={report.userUUID}
>
{report.targetDisplayName || report.targetUsername}
@@ -1,15 +1,15 @@
import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { apiUrl } from '$lib/server/api';
import { apiUrl } from '#lib/server/api';
import {
getServerToken,
getUserFromToken,
clearServerTokens,
hasRole,
roles
} from '$lib/utils/auth';
import type { ReportListResponse } from '$lib/types/report';
import { extractError } from '$lib/utils/misc';
} from '#lib/utils/auth';
import type { ReportListResponse } from '#lib/types/report';
import { extractError } from '#lib/utils/misc';
function normalizeTarget(value: string | null): 'all' | 'pastes' | 'users' {
if (value === 'pastes' || value === 'users') return value;
@@ -5,8 +5,8 @@
import type { PageData } from './$types';
import { resolve } from '$app/paths';
import { goto } from '$app/navigation';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '$lib/types/report';
import { tooltip } from '$lib/utils/misc';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '#lib/types/report';
import { tooltip } from '#lib/utils/misc';
import { SvelteURLSearchParams } from 'svelte/reactivity';
interface Props {
@@ -200,11 +200,11 @@
class="flex cursor-pointer flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
role="link"
tabindex="0"
onclick={() => goto(resolve(`/report/${report.reportID}`))}
onclick={() => goto(resolve(`/report/[reportId]`, { reportId: String(report.reportID)}))}
onkeydown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
goto(resolve(`/report/${report.reportID}`));
goto(resolve(`/report/[reportId]`, { reportId: String(report.reportID)}));
}
}}
>
@@ -221,7 +221,7 @@
<span>{reportTargetLabels[report.targetType] ?? 'Unknown'}</span>
{#if report.pasteId}
<a
href={resolve(`/${report.pasteId}`)}
href={resolve(`/[id]`, { id: report.pasteId})}
class="text-neutral-300 hover:text-white"
onclick={stopPropagation(bubble('click'))}
>
@@ -231,7 +231,7 @@
{#if report.userUUID}
{#if report.targetUsername}
<a
href={resolve(`/user/${report.targetUsername}`)}
href={resolve(`/user/[username]`, {username: report.targetUsername})}
class="text-neutral-300 hover:text-white"
use:tooltip={report.userUUID}
onclick={stopPropagation(bubble('click'))}
@@ -244,7 +244,7 @@
{/if}
{#if report.reporterUsername}
<a
href={resolve(`/user/${report.reporterUsername}`)}
href={resolve(`/user/[username]`, { username: report.reporterUsername})}
class="text-neutral-300 hover:text-white"
use:tooltip={report.reporterUUID}
onclick={stopPropagation(bubble('click'))}
@@ -1,5 +1,5 @@
import { apiUrl } from '$lib/server/api';
import { extractError } from '$lib/utils/misc';
import { apiUrl } from '#lib/server/api';
import { extractError } from '#lib/utils/misc';
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
@@ -1,6 +1,6 @@
<script lang="ts">
import { resolve } from '$app/paths';
import { extractError } from '$lib/utils/misc';
import { extractError } from '#lib/utils/misc';
import { Check, X } from '@lucide/svelte';
import { slide, fade } from 'svelte/transition';
import type { PageData } from './$types';
@@ -1,7 +1,7 @@
import type { PageServerLoad } from './$types';
import { apiUrl } from '$lib/server/api';
import { apiUrl } from '#lib/server/api';
import { error, isHttpError } from '@sveltejs/kit';
import { extractError } from '$lib/utils/misc';
import { extractError } from '#lib/utils/misc';
export const load: PageServerLoad = async ({ fetch }) => {
try {
@@ -1,6 +1,6 @@
<script lang="ts">
import type { PageData } from './$types';
import { formatBytes, formatNumber, tooltip } from '$lib/utils/misc';
import { formatBytes, formatNumber, tooltip } from '#lib/utils/misc';
import { FileText, Users, Database, TrendingUp } from '@lucide/svelte';
interface Props {
@@ -1,11 +1,11 @@
import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { apiUrl } from '$lib/server/api';
import { getServerToken } from '$lib/utils/auth';
import type { User } from '$lib/types/user';
import type { Paste } from '$lib/types/paste';
import type { Pagination } from '$lib/types/pagination';
import type { Report, ReportListResponse } from '$lib/types/report';
import { apiUrl } from '#lib/server/api';
import { getServerToken } from '#lib/utils/auth';
import type { User } from '#lib/types/user';
import type { Paste } from '#lib/types/paste';
import type { Pagination } from '#lib/types/pagination';
import type { Report, ReportListResponse } from '#lib/types/report';
function decodeJwtRoles(token?: string | null): number {
try {
@@ -6,7 +6,7 @@
import { goto, afterNavigate } from '$app/navigation';
import { page } from '$app/state';
import type { PageData } from './$types';
import type { Pagination } from '$lib/types/pagination';
import type { Pagination } from '#lib/types/pagination';
import {
User,
CalendarDays,
@@ -30,13 +30,13 @@
tooltip,
dateToRelativeString,
extractError
} from '$lib/utils/misc';
import { clearTokens, getToken, hasRole, roles } from '$lib/utils/auth';
import { openModal } from '$lib/stores/modal';
import { user } from '$lib/stores/user';
} from '#lib/utils/misc';
import { clearTokens, getToken, hasRole, roles } from '#lib/utils/auth';
import { openModal } from '#lib/stores/modal';
import { user } from '#lib/stores/user';
import { onMount } from 'svelte';
import Paste from '$lib/components/Paste.svelte';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '$lib/types/report';
import Paste from '#lib/components/Paste.svelte';
import { reportStatusLabels, reportTargetLabels, reportTypeLabels } from '#lib/types/report';
import { fade } from 'svelte/transition';
interface Props {
@@ -1676,11 +1676,11 @@
class="flex cursor-pointer flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
role="link"
tabindex="0"
onclick={() => goto(resolve(`/report/${report.reportID}`))}
onclick={() => goto(resolve(`/report/[reportId]`, { reportId: String(report.reportID)}))}
onkeydown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
goto(resolve(`/report/${report.reportID}`));
goto(resolve(`/report/[reportId]`, { reportId: String(report.reportID)}));
}
}}
>
@@ -1697,7 +1697,7 @@
<span>{reportTargetLabels[report.targetType] ?? 'Unknown'}</span>
{#if report.pasteId}
<a
href={resolve(`/${report.pasteId}`)}
href={resolve(`/[id]`, {id:report.pasteId})}
class="text-neutral-300 hover:text-white"
onclick={stopPropagation(bubble('click'))}
>
@@ -1707,7 +1707,7 @@
{#if report.userUUID}
{#if report.targetUsername}
<a
href={resolve(`/user/${report.targetUsername}`)}
href={resolve(`/user/[username]`, { username: report.targetUsername})}
class="text-neutral-300 hover:text-white"
use:tooltip={report.userUUID}
onclick={stopPropagation(bubble('click'))}
@@ -1735,11 +1735,11 @@
class="flex cursor-pointer flex-col gap-2 rounded border border-neutral-700 bg-neutral-800 px-5 py-4 transition-colors duration-200 hover:bg-neutral-700 focus:ring-2 focus:ring-neutral-600 focus:outline-none"
role="link"
tabindex="0"
onclick={() => goto(resolve(`/report/${report.reportID}`))}
onclick={() => goto(resolve(`/report/[reportId]`, { reportId: String(report.reportID)}))}
onkeydown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
goto(resolve(`/report/${report.reportID}`));
goto(resolve(`/report/[reportId]`, { reportId: String(report.reportID)}));
}
}}
>
@@ -1756,7 +1756,7 @@
<span>{reportTargetLabels[report.targetType] ?? 'Unknown'}</span>
{#if report.reporterUsername}
<a
href={resolve(`/user/${report.reporterUsername}`)}
href={resolve(`/user/[username]`, { username: report.reporterUsername})}
class="text-neutral-300 hover:text-white"
use:tooltip={report.reporterUUID}
onclick={stopPropagation(bubble('click'))}
@@ -1768,7 +1768,7 @@
{/if}
{#if report.pastePID}
<a
href={resolve(`/${report.pasteId ?? report.pastePID}`)}
href={resolve(`/[id]`, { id: report.pasteId ?? ""})}
class="text-neutral-300 hover:text-white"
onclick={stopPropagation(bubble('click'))}
>
@@ -1778,7 +1778,7 @@
{#if report.userUUID}
{#if report.targetUsername}
<a
href={resolve(`/user/${report.targetUsername}`)}
href={resolve(`/user/[username]`, { username: report.targetUsername})}
class="text-neutral-300 hover:text-white"
use:tooltip={report.userUUID}
onclick={stopPropagation(bubble('click'))}
@@ -1,7 +1,7 @@
import type { RequestEvent } from '@sveltejs/kit';
import { error, redirect } from '@sveltejs/kit';
import { apiUrl } from '$lib/server/api';
import { getServerToken } from '$lib/utils/auth';
import { apiUrl } from '#lib/server/api';
import { getServerToken } from '#lib/utils/auth';
export const load = async ({ params, fetch, cookies }: RequestEvent) => {
const token = getServerToken(cookies);
@@ -1,5 +1,5 @@
import { apiUrl } from '$lib/server/api';
import { extractError } from '$lib/utils/misc';
import { apiUrl } from '#lib/server/api';
import { extractError } from '#lib/utils/misc';
import { error } from '@sveltejs/kit';
export const load = async ({ url, request }) => {
-18
View File
@@ -1,18 +0,0 @@
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://svelte.dev/docs/kit/integrations
// for more information about preprocessors
preprocess: vitePreprocess(),
kit: {
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter()
}
};
export default config;
+8 -3
View File
@@ -1,5 +1,7 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"extends": "$app/tsconfig",
"include": ["src", "test", "*"],
"exclude": ["src/service-worker"],
"compilerOptions": {
"rewriteRelativeImportExtensions": true,
"allowJs": true,
@@ -10,10 +12,13 @@
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "bundler"
"moduleResolution": "bundler",
"paths": {
"#lib/*": ["./src/lib/*"]
}
}
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
// except #lib which is handled by https://svelte.dev/docs/kit/configuration#files
//
// To make changes to top-level options such as include and exclude, we recommend extending
// the generated config; see https://svelte.dev/docs/kit/configuration#typescript
+3 -1
View File
@@ -1,5 +1,7 @@
import tailwindcss from '@tailwindcss/vite';
import { sveltekit } from '@sveltejs/kit/vite';
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { defineConfig } from 'vite';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
@@ -14,7 +16,7 @@ const allowedHosts = process.env.VITE_ALLOWED_HOSTS
: ['localhost'];
export default defineConfig({
plugins: [tailwindcss(), sveltekit()],
plugins: [tailwindcss(), sveltekit({ adapter: adapter(), preprocess: vitePreprocess() })],
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
COMMIT_HASH: JSON.stringify(process.env.GIT_COMMIT_HASH || 'unknown')
+10 -6
View File
@@ -13,14 +13,18 @@ This is the backend API for SharpbinV3, built with ASP.NET Core and Entity Frame
The server configuration is managed in `appsettings.json`. For development, ensure you have set the following in `appsettings.Development.json` or as environment variables:
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=/app/data/sharpbin.db`).
- `JwtSettings__Secret`: A secure string used for signing JWT tokens.
- `PasteSettings__View_HMAC_Secret`: Required to securely hash viewer identifiers
- `PasteSettings__View_Internal_API_Key`: Enforces views to be counted/recorded only by the frontend, if set it needs to be the same for both backend and frontend.
- `ConnectionStrings__DefaultConnection`: SQLite connection string (e.g., `Data Source=sharpbin.db` locally). Compose defaults to `Data Source=/app/data/sharpbin.db`.
- `JwtSettings__Secret`: A random secret of 32–128 characters used for signing JWT tokens.
- `PasteSettings__View_HMAC_Secret`: A required random secret of 32–128 characters used to hash viewer identifiers.
- `PasteSettings__View_Internal_API_Key`: A shared key of 32–128 characters used to authorize view recording. Compose passes it to both services. For standalone deployments, match the frontend's `VIEW_INTERNAL_API_KEY`.
For Docker Compose, configure the backend in the root `.env` file. The image includes `appsettings.json` defaults, and environment variables override them. No host configuration mount is required.
The development frontend uses a fixed internal key matching the checked-in `appsettings.Development.json`. Changing only the backend key will break development view recording. Use generated secrets for deployment; see the [root configuration guide](../README.md#configuration).
### Database Migrations
Apply the database migrations to initialize the SQLite database:
The backend applies database migrations automatically on startup. To apply them manually before starting it:
```bash
dotnet ef database update
@@ -34,4 +38,4 @@ Use the following command to run the server with hot reload:
dotnet watch run
```
The API will be accessible at http://localhost:5050 by default (check `Properties/launchSettings.json` or your specific configuration).
The API will be accessible at http://localhost:5050 by default (check `Properties/launchSettings.json` or your specific configuration).
@@ -34,10 +34,13 @@
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
<PackageReference Include="Otp.NET" Version="1.4.1" />
<PackageReference Include="SQLitePCLRaw.lib.e_sqlite3" Version="3.53.4.1-pre1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.16.0" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="11.0.0-rc.2.26504.105" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
<EmbeddedResource Include="EmailTemplates\*.html" />
</ItemGroup>
</Project>
-23
View File
@@ -1,23 +0,0 @@
# Required Misc. Variables
Domain=example.com
Https=true
AllowedCorsOrigins__0=https://example.com
JwtSettings__Secret=totally_random_and_secure_string
ConnectionStrings__DefaultConnection=Data Source=/app/data/sharpbin.db
# Auth Settings
AuthSettings__CF_Turnstile_SecretKey=1x0000000000000000000000000000000AA
AuthSettings__CF_Turnstile_SiteKey=3x00000000000000000000FF
AuthSettings__Registration_Enabled=true
AuthSettings__Admins_Require_2FA=true
AuthSettings__API_Key_HMAC_Secret=another_random_and_secure_string
# Paste Settings
PasteSettings__MaxTitleLength=500
PasteSettings__MaxPasteSizeInBytes=1048576
PasteSettings__EnablePasteCompression=true
PasteSettings__RequiresVerification=true
PasteSettings__View_HMAC_Secret=random_minimum_32_char_string
# Used so that views are only counted from the frontend
# Must be the same on both the frontend and backend environment
PasteSettings__View_Internal_API_Key=another_random_minimum_32_char_string
+8 -8
View File
@@ -6,13 +6,13 @@ services:
image: sharpbin-backend
container_name: sharpbin-backend
env_file:
- "backend.env"
- ".env"
environment:
DATA_PROTECTION_KEY_PATH: /app/data/keys
ConnectionStrings__DefaultConnection: "Data Source=/app/data/sharpbin.db"
DATA_PROTECTION_KEY_PATH: ${DATA_PROTECTION_KEY_PATH:-/app/data/keys}
ConnectionStrings__DefaultConnection: ${ConnectionStrings__DefaultConnection:-Data Source=/app/data/sharpbin.db}
PasteSettings__View_Internal_API_Key: ${PasteSettings__View_Internal_API_Key:?Set PasteSettings__View_Internal_API_Key in .env}
volumes:
- sharpbin-data:/app/data
- ./SharpbinV3.Server/appsettings.json:/app/appsettings.json
networks:
- sharpbin-net
healthcheck:
@@ -28,13 +28,13 @@ services:
context: ./SharpbinV3.Client
dockerfile: Dockerfile
args:
GIT_COMMIT_HASH: ${GIT_COMMIT_HASH}
GIT_COMMIT_HASH: ${GIT_COMMIT_HASH:-unknown}
image: sharpbin-frontend
container_name: sharpbin-frontend
env_file:
- "frontend.env"
environment:
VITE_API_URL: http://backend:8080
VITE_API_URL: ${VITE_API_URL:-http://backend:8080}
ORIGIN: ${ORIGIN:?Set ORIGIN in .env}
VIEW_INTERNAL_API_KEY: ${PasteSettings__View_Internal_API_Key:?Set PasteSettings__View_Internal_API_Key in .env}
ports:
- "5173:5173"
-6
View File
@@ -1,6 +0,0 @@
VITE_API_URL=http://backend:8080
VITE_ALLOWED_HOSTS=localhost,example.com
# Used so that views are only counted from the frontend
# Must be the same on both the frontend and backend environment
# The frontend will also try to parse 'PasteSettings__View_Internal_API_Key'
VIEW_INTERNAL_API_KEY=another_random_minimum_32_char_string