Files
zeekayandHanzo Dev 76aaa4ded8 rebrand: purge upstream branding that still reached users and operators
Audited against the live site, not just the source. git.hanzo.ai renders a
clean DOM already, so what was left was the surface that source greps miss
and live headers show.

The one leak visibly served on every request:

  set-cookie: gitea_incredible=

The remember-me cookie default was never rebranded. Renamed to
hanzo_git_remember; existing remember-me sessions are invalidated once.

The container was branding the site title upstream. Both entrypoints wrote
APP_NAME="Gitea: Git with a cup of tea" into app.ini, overriding the
already-correct Go default. Removed the shell default entirely so the value
lives in exactly one place, setting.AppName; ini MustString fills an empty
key with the default.

Half-finished earlier passes, now finished: the iframe query params were
already hanzo-*, but the postMessage payload keys and the window global
were not; the settings page told users to sign with "-n gitea" while the
verifier is the only thing that has to agree with it, so the namespace is
now one exported constant rendered into the command.

Also: local storage prefix, the fetch-action request header (made
vendor-free per our header convention, both ends are ours), install-form
database prefill, and the shipped example config, which additionally
documented $GITEA_WORK_DIR and $GITEA_CUSTOM -- env vars this fork renamed
to GIT_* long ago -- and a COOKIE_USERNAME key the code no longer reads.

Deleted docker/manifest*.tmpl: dead Drone-era templates publishing to
gitea/gitea on Docker Hub, referenced by nothing. Our docker dry-run was
also pulling build cache from ghcr.io/go-gitea/gitea.

Deliberately left, with reasons:
- "The Gitea Authors" copyright headers (2938) and upstream PR/issue links
  (278). Attribution and provenance; removing them would be wrong.
- /data/gitea on-disk layout. Renaming it is a data migration that orphans
  every existing install's db, sessions, avatars and attachments.
- The "gitea" webhook type and migration source. Wire and DB values, and
  the migration source correctly names a third party we import from, the
  same way github and gitlab do. Display name already reads Hanzo Git.
- X-Gitea-OTP, X-Gitea-Object-Type and the X-Gitea-* webhook delivery
  headers. External client contracts on a live host; renaming them belongs
  in its own change, not a branding sweep.
- gitea-azuread__a and sodipodi:docname in web_src/svg. Verified these never
  reach the DOM: svgo cleanupIds rewrites the ids and removeEditorsNSData
  strips the editor metadata before the asset is written.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-26 11:30:33 -07:00

95 lines
4.4 KiB
TypeScript

import {generateElemId} from '../utils/dom.ts';
import {errorMessage} from '../modules/errors.ts';
import {isDarkTheme} from '../utils.ts';
function safeRenderIframeLink(link: any): string | null {
try {
const url = new URL(link, window.location.href);
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
console.error(`Unsupported link protocol: ${link}`);
return null;
}
return url.href;
} catch (e) {
console.error(`Failed to parse link: ${link}, error: ${errorMessage(e)}`);
return null;
}
}
// This function is only designed for "open-link" command from iframe, is not suitable for other contexts.
// Because other link protocols are directly handled by the iframe, but not here.
// Arguments can be any type & any value, they are from "message" event's data which is not controlled by us.
export function navigateToIframeLink(unsafeLink: any, target: any) {
const linkHref = safeRenderIframeLink(unsafeLink);
if (linkHref === null) return;
if (target === '_blank') {
window.open(linkHref, '_blank', 'noopener,noreferrer');
return;
}
// treat all other targets including ("_top", "_self", etc.) as same tab navigation
window.location.assign(linkHref);
}
function getRealBackgroundColor(el: HTMLElement) {
for (let n = el; n; n = n.parentElement!) {
const style = window.getComputedStyle(n);
const bgColor = style.backgroundColor;
// 'rgba(0, 0, 0, 0)' is how most browsers represent transparent
if (bgColor !== 'rgba(0, 0, 0, 0)' && bgColor !== 'transparent') {
return bgColor;
}
}
return '';
}
export async function initExternalRenderIframe(iframe: HTMLIFrameElement) {
const iframeSrcUrl = iframe.getAttribute('data-src')!;
if (!iframe.id) iframe.id = generateElemId('hanzo-iframe-');
window.addEventListener('message', (e) => {
if (e.source !== iframe.contentWindow) return;
if (!e.data?.hanzoIframeCmd || e.data?.hanzoIframeId !== iframe.id) return;
const cmd = e.data.hanzoIframeCmd;
if (cmd === 'resize') {
iframe.style.height = `${e.data.iframeHeight}px`;
} else if (cmd === 'open-link') {
navigateToIframeLink(e.data.openLink, e.data.anchorTarget);
} else {
throw new Error(`Unknown iframe cmd: ${cmd}`);
}
});
const u = new URL(iframeSrcUrl, window.location.origin);
u.searchParams.set('hanzo-is-dark-theme', String(isDarkTheme()));
u.searchParams.set('hanzo-iframe-id', iframe.id);
u.searchParams.set('hanzo-iframe-bgcolor', getRealBackgroundColor(iframe));
// There are 3 kinds of external render modes:
// * external frontend render:
// * parent page creates iframe, iframe navigates to render page
// * render generates frame page with external-render-helper (injected), external-render-frontend and file content (hidden textarea)
// * frame page executes external-render-frontend JS code to finds a frontend plugin to render
// * external backend render (HTML)
// * parent page creates iframe, iframe navigates to render page
// * render executes command to generate rendered HTML content with external-render-helper (injected)
// * frame page displays the rendered content
// * external backend render (non-HTML, e.g.: PDF, image)
// * parent page creates iframe, iframe navigates to render page
// * render executes command to generate rendered content
// * response header is automatically detected from rendered content
// It must use "src" here, because the frame content should not inherit parent's CSP.
// Otherwise, "srcdoc" makes the frame content inherit the parent's CSP,
// then some renders like "asciicast (asciinema)" which require "unsafe-eval" won't work.
//
// When using "src", Chrome can report false-alarm error like:
// * Unsafe attempt to load URL http://localhost/owner/repo/render/branch/main/file from frame with URL http://localhost/owner/repo/render/branch/main/file. Domains, protocols and ports must match.
// (only for the first time that the developer opens the browser console)
// Such error log can also appear even if you access the link "http://.../owner/repo/render/branch/main/file" directly.
// Everything just works, it is just a false-alarm caused by Chrome's Developer Tools, so such error log can be ignored.
//
// Another reason for why "src" is a must: if the render outputs non-HTML contents like PDF or image,
// Only "src" can correctly load and display the rendered content, "srcdoc" won't work.
iframe.src = u.href;
}