Guard every feed-, board-, discovery- or user-supplied link with safeUrl

roles.js already checked a role's original_url is http(s) before
putting it in an href, so a board that wrote something other than a
URL could not make the reader navigate to it; sources.js (a search
sample's row.url), companies.js (careers_url) and applications.js
(application.url) put the same kind of outside data straight into a
link unchecked.

safeUrl moves to app.js, beside the app's other shared helpers, and
is exported the same way; a link whose safeUrl comes back empty is
now left out of the page (plain text) instead of getting an href of
"".

Co-Authored-By: Claude Sonnet <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet committed 2026-09-29 15:24:54 +02:00
1 parent 4fb9e801f5
commit 5dfaa393be
6 files changed
+40 -20

No files matched your search

+16 -4
View File
@@ -14,9 +14,10 @@
* forgetting the header is the failure that looks like a server bug.
*
* Beside `api` on `window`, the few helpers more than one page script uses:
* `count`, `cell`, `debounce`, and the company list with its affinity control
* (`loadCompanies`, `companies`, `affinityControl`, `setAffinity`). One copy
* each, since two copies of a helper is one of them being fixed.
* `count`, `cell`, `debounce`, `safeUrl`, and the company list with its
* affinity control (`loadCompanies`, `companies`, `affinityControl`,
* `setAffinity`). One copy each, since two copies of a helper is one of them
* being fixed.
*
* Affinity is per search agent. The three company helpers take the agent's
* id as an optional last argument and send it along; a caller that passes
@@ -104,6 +105,17 @@
};
}
/** An `http(s)` URL, or "" for anything else — `javascript:`, a bare path,
empty. Every link whose address came from a feed, a board, discovery or
a person (a search result's `url`, a company's `careers_url`, a saved
application's `url`, a role's `original_url`) goes through this before
it lands in an `href`, so a board that wrote something other than a URL
cannot make this page navigate to it. Moved here from roles.js, which
first needed it for the reader's outbound links. */
function safeUrl(u) {
return /^https?:\/\//i.test(u || "") ? u : "";
}
// --------------------------------------------------------------- companies
/** @type {Map<string, object>} company_key -> row from /api/companies. One
@@ -170,6 +182,6 @@
}
Object.assign(window, {
api, count, cell, debounce, companies, loadCompanies, affinityControl, setAffinity,
api, count, cell, debounce, safeUrl, companies, loadCompanies, affinityControl, setAffinity,
});
})();