Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

feat: adding well-known urls for api, change pass, and security

Mohamed Bassem2620d9e6a79d
diff --git a/apps/landing/public/.well-known/security.txt b/apps/landing/public/.well-known/security.txt
new file mode 100644
index 00000000..6a41beb0
--- /dev/null
+++ b/apps/landing/public/.well-known/security.txt
@@ -0,0 +1,4 @@
+Contact: mailto:[email protected]
+Expires: 2027-08-01T00:00:00Z
+Canonical: https://karakeep.app/.well-known/security.txt
+Preferred-Languages: en
diff --git a/apps/web/app/.well-known/api-catalog/route.ts b/apps/web/app/.well-known/api-catalog/route.ts
new file mode 100644
index 00000000..fb5a41cd
--- /dev/null
+++ b/apps/web/app/.well-known/api-catalog/route.ts
@@ -0,0 +1,61 @@
+import serverConfig from "@karakeep/shared/config";
+
+const API_CATALOG_PROFILE = "https://www.rfc-editor.org/info/rfc9727";
+const API_DOCUMENTATION_URL = "https://docs.karakeep.app/api";
+const OPENAPI_SPEC_URL =
+ "https://raw.githubusercontent.com/karakeep-app/karakeep/refs/heads/main/packages/open-api/karakeep-openapi-spec.json";
+
+function apiCatalogUrl() {
+ return `${serverConfig.publicUrl}/.well-known/api-catalog`;
+}
+
+function responseHeaders() {
+ return {
+ "Cache-Control": "public, max-age=3600",
+ "Content-Type": `application/linkset+json; profile="${API_CATALOG_PROFILE}"`,
+ Link: `<${apiCatalogUrl()}>; rel="api-catalog"`,
+ };
+}
+
+export function GET() {
+ const apiBaseUrl = `${serverConfig.publicUrl}/api/v1`;
+ const catalog = {
+ linkset: [
+ {
+ anchor: apiCatalogUrl(),
+ item: [{ href: apiBaseUrl }],
+ },
+ {
+ anchor: apiBaseUrl,
+ "service-desc": [
+ {
+ href: OPENAPI_SPEC_URL,
+ type: "application/json",
+ },
+ ],
+ "service-doc": [
+ {
+ href: API_DOCUMENTATION_URL,
+ type: "text/html",
+ },
+ ],
+ status: [
+ {
+ href: `${serverConfig.publicUrl}/api/health`,
+ type: "application/json",
+ },
+ ],
+ },
+ ],
+ };
+
+ return new Response(JSON.stringify(catalog), {
+ headers: responseHeaders(),
+ });
+}
+
+export function HEAD() {
+ return new Response(null, {
+ headers: responseHeaders(),
+ });
+}
diff --git a/apps/web/app/.well-known/change-password/route.ts b/apps/web/app/.well-known/change-password/route.ts
new file mode 100644
index 00000000..7b82ba2f
--- /dev/null
+++ b/apps/web/app/.well-known/change-password/route.ts
@@ -0,0 +1,11 @@
+const CHANGE_PASSWORD_PATH = "/settings/info#security";
+
+export function GET() {
+ return new Response(null, {
+ status: 302,
+ headers: {
+ "Cache-Control": "no-store",
+ Location: CHANGE_PASSWORD_PATH,
+ },
+ });
+}
diff --git a/apps/web/app/.well-known/security.txt/route.ts b/apps/web/app/.well-known/security.txt/route.ts
new file mode 100644
index 00000000..09c6f087
--- /dev/null
+++ b/apps/web/app/.well-known/security.txt/route.ts
@@ -0,0 +1,25 @@
+import serverConfig from "@karakeep/shared/config";
+
+const SECURITY_TXT_EXPIRY = "2027-08-01T00:00:00Z";
+
+export function GET() {
+ const canonicalUrl = new URL(
+ "/.well-known/security.txt",
+ serverConfig.publicUrl,
+ );
+ const lines = [
+ "Contact: mailto:[email protected]",
+ `Expires: ${SECURITY_TXT_EXPIRY}`,
+ ...(canonicalUrl.protocol === "https:"
+ ? [`Canonical: ${canonicalUrl.toString()}`]
+ : []),
+ "Preferred-Languages: en",
+ ];
+
+ return new Response(`${lines.join("\n")}\n`, {
+ headers: {
+ "Cache-Control": "public, max-age=3600",
+ "Content-Type": "text/plain; charset=utf-8",
+ },
+ });
+}
diff --git a/apps/web/app/.well-known/well-known.test.ts b/apps/web/app/.well-known/well-known.test.ts
new file mode 100644
index 00000000..a25a81b7
--- /dev/null
+++ b/apps/web/app/.well-known/well-known.test.ts
@@ -0,0 +1,58 @@
+import { describe, expect, test } from "vitest";
+
+import {
+ GET as getApiCatalog,
+ HEAD as headApiCatalog,
+} from "./api-catalog/route";
+import { GET as getChangePassword } from "./change-password/route";
+import { GET as getSecurityTxt } from "./security.txt/route";
+
+describe("well-known routes", () => {
+ test("serves security.txt with the required fields", async () => {
+ const response = getSecurityTxt();
+ const body = await response.text();
+
+ expect(response.status).toBe(200);
+ expect(response.headers.get("Content-Type")).toBe(
+ "text/plain; charset=utf-8",
+ );
+ expect(body).toContain("Contact: mailto:[email protected]\n");
+ expect(body).toContain("Expires: 2027-08-01T00:00:00Z\n");
+ expect(body).toContain("Preferred-Languages: en\n");
+ });
+
+ test("redirects password managers to account security settings", () => {
+ const response = getChangePassword();
+
+ expect(response.status).toBe(302);
+ expect(response.headers.get("Location")).toBe("/settings/info#security");
+ expect(response.headers.get("Cache-Control")).toBe("no-store");
+ });
+
+ test("serves an RFC 9727 API catalog", async () => {
+ const response = getApiCatalog();
+ const body = (await response.json()) as {
+ linkset: {
+ anchor: string;
+ item?: { href: string }[];
+ }[];
+ };
+
+ expect(response.status).toBe(200);
+ expect(response.headers.get("Content-Type")).toBe(
+ 'application/linkset+json; profile="https://www.rfc-editor.org/info/rfc9727"',
+ );
+ expect(response.headers.get("Link")).toContain('rel="api-catalog"');
+ expect(body.linkset[0]?.item?.[0]?.href).toBe(
+ "http://localhost:3000/api/v1",
+ );
+ });
+
+ test("serves API catalog headers for HEAD requests", async () => {
+ const response = headApiCatalog();
+
+ expect(response.status).toBe(200);
+ expect(response.headers.get("Link")).toContain('rel="api-catalog"');
+ expect(await response.text()).toBe("");
+ });
+});
diff --git a/apps/web/components/settings/ChangePassword.tsx b/apps/web/components/settings/ChangePassword.tsx
index 8513596e..cc66bb1d 100644
--- a/apps/web/components/settings/ChangePassword.tsx
+++ b/apps/web/components/settings/ChangePassword.tsx
@@ -70,7 +70,7 @@ export function ChangePassword() {
}
return (
- <SettingsSection title="Security">
+ <SettingsSection id="security" title="Security">
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<FormField
diff --git a/apps/web/components/settings/SettingsPage.tsx b/apps/web/components/settings/SettingsPage.tsx
index f34aeb46..9f7253e4 100644
--- a/apps/web/components/settings/SettingsPage.tsx
+++ b/apps/web/components/settings/SettingsPage.tsx
@@ -36,12 +36,14 @@ export function SettingsPage({
}
export function SettingsSection({
+ id,
title,
description,
action,
children,
variant = "default",
}: {
+ id?: string;
title?: string;
description?: string;
action?: React.ReactNode;
@@ -50,6 +52,7 @@ export function SettingsSection({
}) {
return (
<Card
+ id={id}
className={variant === "danger" ? "border-destructive/20" : undefined}
>
{(title || description || action) && (