-
Notifications
You must be signed in to change notification settings - Fork 5
Stop logging auth payloads; stop prerendering image URLs #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1edd2f2
Stop logging auth payloads; stop prerendering image URLs
Jan0707 f03ffa9
Address review: only skip the image crawl when a server will serve /_ipx
Jan0707 2e2a79c
Normalise CMS-entered external links so they cannot resolve into our …
Jan0707 19b99e4
Resolve social handles by platform, and fix schemeless links in rich …
Jan0707 10fcaaa
Drop the static-generation script
Jan0707 e2eef86
Potential fix for pull request finding
Jan0707 1284a5f
Potential fix for pull request finding
Jan0707 4054be9
Fix the typecheck regression from the scheme allowlist
Jan0707 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /** | ||
| * The kind of link a CMS field is meant to hold. | ||
| * | ||
| * Anything other than `web` can also accept a bare handle, because that is what editors tend to type | ||
| * into a social field. Knowing the platform is what makes a handle resolvable: `t.muelleer` is a | ||
| * perfectly good Instagram username but reads like a hostname, and only the field it came from can | ||
| * settle which was meant. | ||
| */ | ||
| export type ExternalUrlKind = | ||
| 'web' | 'twitter' | 'instagram' | 'linkedin' | 'github' | 'youtube' | 'bluesky' | 'mastodon' | ||
|
|
||
| interface PlatformRules { | ||
| /** Hosts that mean "this is already a URL, just missing its scheme". */ | ||
| hosts: string[] | ||
| /** Builds a profile URL from a bare handle, or returns undefined if it cannot. */ | ||
| profileUrl: ((handle: string) => string | undefined) | null | ||
| } | ||
|
|
||
| const PLATFORMS: Record<ExternalUrlKind, PlatformRules> = { | ||
| // A website field has no handle form — a value with no host is simply unusable. | ||
| web: { hosts: [], profileUrl: null }, | ||
| twitter: { | ||
| hosts: ['twitter.com', 'www.twitter.com', 'x.com', 'www.x.com'], | ||
| profileUrl: (handle) => `https://twitter.com/${handle}`, | ||
| }, | ||
| instagram: { | ||
| hosts: ['instagram.com', 'www.instagram.com'], | ||
| profileUrl: (handle) => `https://www.instagram.com/${handle}`, | ||
| }, | ||
| linkedin: { | ||
| // Personal profiles live under /in/. Company pages use /company/ and are always pasted as a | ||
| // full URL, so they take the absolute path through this function. | ||
| hosts: ['linkedin.com', 'www.linkedin.com'], | ||
| profileUrl: (handle) => `https://www.linkedin.com/in/${handle}`, | ||
| }, | ||
| github: { | ||
| hosts: ['github.com', 'www.github.com'], | ||
| profileUrl: (handle) => `https://github.com/${handle}`, | ||
| }, | ||
| youtube: { | ||
| // YouTube handles are @-prefixed in URLs, unlike the others. | ||
| hosts: ['youtube.com', 'www.youtube.com', 'youtu.be'], | ||
| profileUrl: (handle) => `https://www.youtube.com/@${handle}`, | ||
| }, | ||
| bluesky: { | ||
| // Bluesky handles are themselves domains (`someone.bsky.social`), so a dot means nothing here. | ||
| hosts: ['bsky.app', 'www.bsky.app'], | ||
| profileUrl: (handle) => `https://bsky.app/profile/${handle}`, | ||
| }, | ||
| mastodon: { | ||
| // Federated, so the instance is part of the handle: `@user@instance.social`. | ||
| hosts: [], | ||
| profileUrl: (handle) => { | ||
| const [user, instance] = handle.split('@') | ||
| return user && instance ? `https://${instance}/@${user}` : undefined | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| /** | ||
| * Makes a CMS-entered link safe to put in an `href`, or returns `undefined` if it cannot be. | ||
| * | ||
| * Editors leave the scheme off — `www.linkedin.com/in/someone` rather than | ||
| * `https://www.linkedin.com/in/someone`. A browser resolves that against the current page, so the link | ||
| * lands on `/hall-of-fame/www.linkedin.com/in/someone` and shows the visitor a 404 on our own domain | ||
| * instead of taking them to the profile. | ||
| * | ||
| * They also paste bare handles into social fields. With `kind` set, those become real profile URLs; | ||
| * with `kind` left at `web`, a value that cannot be a host is dropped rather than guessed at. | ||
| * | ||
| * Whatever comes back is absolute, root-relative, or `undefined` — never something a browser would | ||
| * resolve against the current page. Callers should omit the link entirely for `undefined`. | ||
| * | ||
| * @param url The raw value from the CMS. | ||
| * @param kind Which field it came from. Defaults to `web`. | ||
| * | ||
| * @returns A URL safe to use as an `href`, or `undefined`. | ||
| */ | ||
| export function normalizeExternalUrl( | ||
| url: string | null | undefined, | ||
| kind: ExternalUrlKind = 'web' | ||
| ): string | undefined { | ||
| const trimmed = url?.trim() | ||
|
|
||
| if (!trimmed) { | ||
| return undefined | ||
| } | ||
|
|
||
| // The only schemes worth putting in an href from a CMS field. | ||
| if (/^(https?|mailto|tel):/i.test(trimmed)) { | ||
| return trimmed | ||
| } | ||
|
|
||
| // Any other scheme — `javascript:`, `vbscript:`, `data:` — is dropped rather than passed through. | ||
| // This also drops a host with an explicit port (`example.com:8080/x`), which is indistinguishable | ||
| // from a scheme here; dropping the link is the safe side of that ambiguity, and no CMS value has | ||
| // one. Written as two tests rather than a capture group because `match()[1]` is | ||
| // `string | undefined` under `noUncheckedIndexedAccess`. | ||
| if (/^[a-z][a-z0-9+.-]*:/i.test(trimmed)) { | ||
| return undefined | ||
| } | ||
|
|
||
| // Protocol-relative, or deliberately site-internal. | ||
| if (trimmed.startsWith('//') || trimmed.startsWith('/')) { | ||
| return trimmed | ||
| } | ||
|
|
||
| const rules = PLATFORMS[kind] | ||
| const host = (trimmed.split(/[/?#]/)[0] ?? '').toLowerCase() | ||
|
|
||
| // A URL missing only its scheme: either it names one of the platform's own hosts, or it has a path | ||
| // after something host-shaped, which a handle never does. | ||
| if (rules.hosts.includes(host) || (host.includes('.') && trimmed.includes('/'))) { | ||
| return `https://${trimmed}` | ||
| } | ||
|
|
||
| if (rules.profileUrl) { | ||
| // The `@` is how people write handles; it is not part of the URL for any platform except | ||
| // Mastodon, where it separates user from instance, and YouTube, which re-adds its own. | ||
| const handle = kind === 'mastodon' ? trimmed.replace(/^@/, '') : trimmed.replace(/^@+/, '') | ||
| return handle ? rules.profileUrl(handle) : undefined | ||
| } | ||
|
|
||
| // `web`: no handle form, so the value has to stand up as a host on its own. | ||
| return host.includes('.') ? `https://${trimmed}` : undefined | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.