Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

# Report dependency vulnerabilities without blocking until the baseline is remediated.
- name: Dependency audit
continue-on-error: true
run: pnpm audit --prod --audit-level=high

- name: Lint
run: pnpm lint

Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

- Store extracted article body images under per-user, ownership-checked paths so users cannot read each other's images; add `ALLOW_LEGACY_SHARED_ARTICLES` to keep older articles rendering during migration.
- Scope highlight and tag enrichment to the requesting user across home, upcoming, and search.
- Validate image uploads by sniffing file content instead of trusting filename or Content-Type.
- Gate rate-limit client identification on forwarded headers behind `BEHIND_PROXY`/`TRUSTED_PROXIES`; default to the direct connection IP.
- Assign the first admin account atomically so concurrent initial sign-ups settle on exactly one admin.
- Save reading progress when closing the tab via a keepalive request instead of dropping the final update.
- Stop retrying non-idempotent actions such as link create/delete, and drop auth errors from HTTP retry cascades.
- Resume stalled article extraction and reset stuck processing rows instead of skipping retries.
- Align the create-link tag shape between web and server, guarded by a contract test that fails on drift.
- Trim full text content from list and search responses.
- Parallelize home-suggestion reads and collapse short/long reading counts into a single query.
- Declare the generated search index column and indexes in the schema so schema sync cannot drop them.
- Add a production dependency audit step to CI.

## [v0.2.0] - 2026-07-29

- Add user-curated RSS and Atom subscriptions with staged Review, Saved, and Dismissed collections.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,5 @@ STORAGE_SECRET_ACCESS_KEY=<your-cloudflare-r2-secret-access-key>
## Operational Notes

- Article extraction uses a Playwright-compatible Camoufox websocket configured by `BROWSER_URL`.
- Rate-limit IP trust stays on the socket peer by default; set `BEHIND_PROXY=true` or `TRUSTED_PROXIES` before trusting forwarded headers.
- Local storage is available by default; S3-compatible storage is supported through server env vars.
7 changes: 7 additions & 0 deletions apps/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ REDIS_PORT=6379
# Rate limiting
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX=50
BEHIND_PROXY=false
TRUSTED_PROXIES=

# Body size limit (in bytes)
BODY_SIZE_LIMIT=102400
Expand All @@ -43,6 +45,11 @@ PUBLIC_URL=http://localhost:3000
STORAGE_PROVIDER=local
STORAGE_PATH=./data/storage

# Existing deployments only: serve article body images extracted before per-user storage
# (shared/articles/*). Leave false for fresh installs; set true to keep older articles rendering
# until their images are backfilled, then set false again.
ALLOW_LEGACY_SHARED_ARTICLES=false

# S3-compatible storage (optional; required only when STORAGE_PROVIDER=s3)
S3_ENDPOINT=
S3_REGION=auto
Expand Down
3 changes: 3 additions & 0 deletions apps/server/.env.test.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ REDIS_PORT=6379

RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX=50
BEHIND_PROXY=false
TRUSTED_PROXIES=
BODY_SIZE_LIMIT=102400

PUBLIC_URL=http://localhost:3000
STORAGE_PROVIDER=local
STORAGE_PATH=./data/storage-test
ALLOW_LEGACY_SHARED_ARTICLES=false

S3_ENDPOINT=
S3_REGION=auto
Expand Down
73 changes: 73 additions & 0 deletions apps/server/src/db/migrations/meta/0005_snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,16 @@
"primaryKey": false,
"notNull": false
},
"search_vector": {
"name": "search_vector",
"type": "tsvector",
"primaryKey": false,
"notNull": false,
"generated": {
"as": "setweight(to_tsvector('simple', COALESCE(title, '')), 'A') ||\n setweight(to_tsvector('simple', COALESCE(excerpt, '')), 'B') ||\n setweight(to_tsvector('simple', COALESCE(text_content, '')), 'C')",
"type": "stored"
}
},
"author": {
"name": "author",
"type": "text",
Expand Down Expand Up @@ -1605,6 +1615,69 @@
"concurrently": false,
"method": "btree",
"with": {}
},
"idx_links_search_vector": {
"name": "idx_links_search_vector",
"columns": [
{
"expression": "search_vector",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "gin",
"with": {}
},
"idx_links_title_trgm": {
"name": "idx_links_title_trgm",
"columns": [
{
"expression": "title",
"isExpression": false,
"asc": true,
"nulls": "last",
"opclass": "gin_trgm_ops"
}
],
"isUnique": false,
"concurrently": false,
"method": "gin",
"with": {}
},
"idx_links_url_trgm": {
"name": "idx_links_url_trgm",
"columns": [
{
"expression": "url",
"isExpression": false,
"asc": true,
"nulls": "last",
"opclass": "gin_trgm_ops"
}
],
"isUnique": false,
"concurrently": false,
"method": "gin",
"with": {}
},
"idx_links_excerpt_trgm": {
"name": "idx_links_excerpt_trgm",
"columns": [
{
"expression": "excerpt",
"isExpression": false,
"asc": true,
"nulls": "last",
"opclass": "gin_trgm_ops"
}
],
"isUnique": false,
"concurrently": false,
"method": "gin",
"with": {}
}
},
"foreignKeys": {
Expand Down
35 changes: 28 additions & 7 deletions apps/server/src/db/schemas/links.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { sql } from 'drizzle-orm';
import {
boolean,
customType,
index,
integer,
pgTable,
Expand All @@ -16,6 +18,12 @@ import { importSessionsTable } from './import-sessions.js';
import { tagsTable } from './tags.js';
import { usersTable } from './users.js';

const tsvector = customType<{ data: string; driverData: string }>({
dataType() {
return 'tsvector';
}
});

export const linksTable = pgTable(
'links',
{
Expand All @@ -28,6 +36,11 @@ export const linksTable = pgTable(
content: text('content'),
textContent: text('text_content'),
excerpt: text('excerpt'),
searchVector: tsvector('search_vector').generatedAlwaysAs(
sql`setweight(to_tsvector('simple', COALESCE(title, '')), 'A') ||
setweight(to_tsvector('simple', COALESCE(excerpt, '')), 'B') ||
setweight(to_tsvector('simple', COALESCE(text_content, '')), 'C')`
),
author: text('author'),
favicon: text('favicon'),
coverImage: text('cover_image'),
Expand Down Expand Up @@ -82,7 +95,11 @@ export const linksTable = pgTable(
index('idx_links_user_created').on(table.userId, table.createdAt.desc()),
index('idx_links_user_last_read_at').on(table.userId, table.lastReadAt.desc()),
index('idx_links_import_session_id').on(table.importSessionId),
index('idx_links_processing_started_at').on(table.processingStartedAt)
index('idx_links_processing_started_at').on(table.processingStartedAt),
index('idx_links_search_vector').using('gin', table.searchVector),
index('idx_links_title_trgm').using('gin', table.title.op('gin_trgm_ops')),
index('idx_links_url_trgm').using('gin', table.url.op('gin_trgm_ops')),
index('idx_links_excerpt_trgm').using('gin', table.excerpt.op('gin_trgm_ops'))
]
);

Expand All @@ -91,7 +108,8 @@ export const selectLinksSchema = createSelectSchema(linksTable).omit({
createdAt: true,
updatedAt: true,
processingStartedAt: true,
importSessionId: true
importSessionId: true,
searchVector: true
});

const tagWithGroupColorSchema = z.object({
Expand All @@ -117,9 +135,11 @@ const linkHighlightSchema = z.object({
export const selectLinksListSchema = createSelectSchema(linksTable)
.omit({
content: true,
textContent: true,
userId: true,
processingStartedAt: true,
importSessionId: true
importSessionId: true,
searchVector: true
})
.extend({
createdAt: z.string().optional(),
Expand All @@ -128,9 +148,11 @@ export const selectLinksListSchema = createSelectSchema(linksTable)
highlights: z.array(linkHighlightSchema)
});

export const selectLinksWithSignedUrlSchema = createSelectSchema(linksTable).extend({
coverImageSignedUrl: z.string().optional()
});
export const selectLinksWithSignedUrlSchema = createSelectSchema(linksTable)
.omit({ searchVector: true })
.extend({
coverImageSignedUrl: z.string().optional()
});

export const insertLinksSchema = createInsertSchema(linksTable).omit({
id: true,
Expand Down Expand Up @@ -173,7 +195,6 @@ export const createLinkSchema = z.object({
tags: z
.array(
z.object({
id: z.string(),
groupId: z.string(),
name: z.string()
})
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/lib/article-url-guard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { isValidUrl } from './url-validator.js';

// Keep this domain-specific assertion separate from browser-request-guard:
// article navigation reports a typed failure to the extraction workflow, while
// browser subresource interception needs a boolean decision per request.
export async function assertSafeArticleUrl(url: string): Promise<void> {
if (!(await isValidUrl(url))) {
throw new Error('Article URL is not allowed');
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/lib/browser-request-guard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { isValidUrl } from './url-validator.js';

// Intentional layering with article-url-guard: browser requests are evaluated
// per subresource and return a boolean for Playwright route handling, whereas
// article navigation uses an exception-oriented domain boundary.
export async function isAllowedBrowserRequestUrl(url: string): Promise<boolean> {
return isValidUrl(url);
}
15 changes: 13 additions & 2 deletions apps/server/src/lib/env-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ const envSchema = z

REDIS_PORT: z.coerce.number().int().positive().default(6379),

RATE_LIMIT_WINDOW_MS: z.coerce.number().int().positive().default(60_000),
BEHIND_PROXY: z
.enum(['true', 'false'])
.default('false')
.transform((value) => value === 'true'),

RATE_LIMIT_MAX: z.coerce.number().int().positive().default(50),
TRUSTED_PROXIES: z.string().default(''),

BODY_SIZE_LIMIT: z.coerce.number().int().positive().default(4_194_304),

Expand All @@ -60,6 +63,14 @@ const envSchema = z

STORAGE_PROVIDER: z.enum(['local', 'local-docker', 's3']).default('local'),

// Serve pre-user-scoping article body images (shared/articles/*) extracted before the
// ownership-checked storage scheme. Leave off for fresh deployments; enable for existing
// installations until their legacy assets are backfilled, then turn off again.
ALLOW_LEGACY_SHARED_ARTICLES: z
.enum(['true', 'false'])
.default('false')
.transform((value) => value === 'true'),

// S3-compatible storage (AWS S3, Cloudflare R2, MinIO, etc.)
// S3_ENDPOINT: omit for AWS S3, set to custom URL for R2/MinIO
S3_ENDPOINT: z.string().default(''),
Expand Down
27 changes: 27 additions & 0 deletions apps/server/src/middlewares/rate-limit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest';

import { resolveRateLimitIpKey } from './rate-limit.js';

describe('resolveRateLimitIpKey', () => {
it('ignores spoofed forwarded headers when proxies are untrusted', () => {
expect(
resolveRateLimitIpKey({
peerIp: '203.0.113.10',
forwardedFor: '198.51.100.23',
realIp: '198.51.100.24',
trustForwardedHeaders: false
})
).toBe('203.0.113.10');
});

it('uses the forwarded client IP when proxies are trusted', () => {
expect(
resolveRateLimitIpKey({
peerIp: '203.0.113.10',
forwardedFor: '198.51.100.23, 198.51.100.24',
realIp: '198.51.100.25',
trustForwardedHeaders: true
})
).toBe('198.51.100.23');
});
});
Loading
Loading