diff --git a/docs/configuration.md b/docs/configuration.md index 1622da6fa414a..8e8654157c249 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -24,6 +24,7 @@ This part of the configuration concerns anything that can affect the whole site. - `pageTitleSuffix`: a string added to the end of the page title. This only applies to the browser tab title, not the title shown at the top of the page. - `enableSPA`: whether to enable [[SPA Routing]] on your site. - `enablePopovers`: whether to enable [[popover previews]] on your site. +- `enablePassProtected`: whether to enable [[Password protected]] on your site. - `analytics`: what to use for analytics on your site. Values can be - `null`: don't use analytics; - `{ provider: 'google', tagId: '' }`: use Google Analytics; diff --git a/docs/features/Password Protected.md b/docs/features/Password Protected.md new file mode 100644 index 0000000000000..6e95dabefb14f --- /dev/null +++ b/docs/features/Password Protected.md @@ -0,0 +1,31 @@ +--- +title: Password Protected +--- + +Some notes may be sensitive, i.e. non-public personal projects, contacts, meeting notes and such. It would be really useful to be able to protect some pages or group of pages so they don't appear to everyone, while still allowing them to be published. + +By adding a password to your note's frontmatter, you can create an extra layer of security, ensuring that only authorized individuals can access your content. Whether you're safeguarding personal journals, project plans, this feature provides the peace of mind you need. + +## How it works + +Simply add a password field to your note's frontmatter and set your desired password. When you try to view the note, you'll be prompted to enter the password. If the password is correct, the note will be unlocked. Once unlocked, you can access the note until you clear your browser cookies. + +### Security techniques + +- Key Derivation: Utilizes PBKDF2 for generating secure encryption keys. +- Unique Salt for Each Encryption: A unique salt is generated every time the encrypt method is used, enhancing security. +- Encryption/Decryption: Implements AES-GCM for robust data encryption and decryption. +- Encoding/Decoding: Use base64 to convert non-textual encrypted data in HTML + +### Disclaimer + +- Use it at your own risk +- You need to choose a strong password and share it only to trusted users +- You need to secure your notes and Quartz repository in private mode on Github/Gitlab/Bitbucket... or use your own Git server +- You can use other WAF tools to enhance security, based on URL of notes that Quartz build for you, e.g. Cloudflare WAF, AWS WAF, Google Cloud Armor... + +## Configuration + +- Disable password protected notes: set the `enablePasswordProtected` field in `quartz.config.ts` to be `false`. +- Style: `quartz/components/styles/passwordProtected.scss` +- Script: `quartz/components/scripts/decrypt.inline.ts` diff --git a/package-lock.json b/package-lock.json index 042a7fcb6c606..783028e1b84a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,6 +54,7 @@ "remark-parse": "^11.0.0", "remark-rehype": "^11.1.1", "remark-smartypants": "^3.0.2", + "rfc4648": "^1.5.3", "rfdc": "^1.4.1", "rimraf": "^6.0.1", "serve-handler": "^6.1.5", @@ -5471,6 +5472,12 @@ "node": ">=0.10.0" } }, + "node_modules/rfc4648": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/rfc4648/-/rfc4648-1.5.3.tgz", + "integrity": "sha512-MjOWxM065+WswwnmNONOT+bD1nXzY9Km6u3kzvnx8F8/HXGZdz3T6e6vZJ8Q/RIMUSp/nxqjH3GwvJDy8ijeQQ==", + "license": "MIT" + }, "node_modules/rfdc": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", diff --git a/package.json b/package.json index a5178735ea005..db4ef33d46694 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "remark-parse": "^11.0.0", "remark-rehype": "^11.1.1", "remark-smartypants": "^3.0.2", + "rfc4648": "^1.5.3", "rfdc": "^1.4.1", "rimraf": "^6.0.1", "serve-handler": "^6.1.5", diff --git a/quartz.config.ts b/quartz.config.ts index e96ee4843fda1..4cc2af2b8bd93 100644 --- a/quartz.config.ts +++ b/quartz.config.ts @@ -12,6 +12,7 @@ const config: QuartzConfig = { pageTitleSuffix: "", enableSPA: true, enablePopovers: true, + enablePassProtected: true, analytics: { provider: "plausible", }, diff --git a/quartz/cfg.ts b/quartz/cfg.ts index 85527a093c410..a3a022a970342 100644 --- a/quartz/cfg.ts +++ b/quartz/cfg.ts @@ -50,6 +50,8 @@ export interface GlobalConfiguration { enableSPA: boolean /** Whether to display Wikipedia-style popovers when hovering over links */ enablePopovers: boolean + /** Whether to enable password protected page rendering */ + enablePassProtected: boolean /** Analytics mode */ analytics: Analytics /** Glob patterns to not search */ diff --git a/quartz/components/pages/EncryptedContent.tsx b/quartz/components/pages/EncryptedContent.tsx new file mode 100644 index 0000000000000..2ef0d9bb1d259 --- /dev/null +++ b/quartz/components/pages/EncryptedContent.tsx @@ -0,0 +1,45 @@ +import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types" +import { i18n } from "../../i18n" + +const EncryptedContent: QuartzComponent = ({ + iteration, + encryptedContent, + cfg, +}: QuartzComponentProps) => { + return ( + <> +
+
+ {i18n(cfg.locale).pages.encryptedContent.enterPassword} +
+
+

+

+ {i18n(cfg.locale).pages.encryptedContent.loading} +

+
+ + +
+
+ + ) +} + +export default (() => EncryptedContent) satisfies QuartzComponentConstructor diff --git a/quartz/components/renderPage.tsx b/quartz/components/renderPage.tsx index f2dcceaa573b5..fbd34806193c4 100644 --- a/quartz/components/renderPage.tsx +++ b/quartz/components/renderPage.tsx @@ -2,7 +2,9 @@ import { render } from "preact-render-to-string" import { QuartzComponent, QuartzComponentProps } from "./types" import HeaderConstructor from "./Header" import BodyConstructor from "./Body" +import EncryptedContent from "./pages/EncryptedContent" import { JSResourceToScriptElement, StaticResources } from "../util/resources" +import { getEncryptedPayload } from "../util/encrypt" import { clone, FullSlug, RelativeURL, joinSegments, normalizeHastElement } from "../util/path" import { visit } from "unist-util-visit" import { Root, Element, ElementContent } from "hast" @@ -53,13 +55,13 @@ export function pageResources( } } -export function renderPage( +export async function renderPage( cfg: GlobalConfiguration, slug: FullSlug, componentData: QuartzComponentProps, components: RenderComponents, pageResources: StaticResources, -): string { +): Promise { // make a deep copy of the tree so we don't remove the transclusion references // for the file cached in contentMap in build.ts const root = clone(componentData.tree) as Root @@ -195,6 +197,7 @@ export function renderPage( } = components const Header = HeaderConstructor() const Body = BodyConstructor() + const Encrypted = EncryptedContent() const LeftComponent = ( - + {content}