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:
1 parent
4fb9e801f5
commit
5dfaa393be
6 files changed
+40
-20
No files matched your search
+13
-7
@@ -14,7 +14,7 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const { api, count, debounce } = window;
|
||||
const { api, count, debounce, safeUrl } = window;
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
|
||||
/** @type {{searches: object[], adzuna_key: boolean}} */
|
||||
@@ -168,12 +168,18 @@
|
||||
const list = $("#search-sample");
|
||||
for (const row of result.sample) {
|
||||
const li = document.createElement("li");
|
||||
const link = document.createElement("a");
|
||||
link.href = row.url;
|
||||
link.target = "_blank";
|
||||
link.rel = "noopener";
|
||||
link.textContent = row.title;
|
||||
li.append(link, ` — ${[row.company, row.place].filter(Boolean).join(", ")}`);
|
||||
const url = safeUrl(row.url);
|
||||
if (url) {
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.target = "_blank";
|
||||
link.rel = "noopener";
|
||||
link.textContent = row.title;
|
||||
li.appendChild(link);
|
||||
} else {
|
||||
li.append(row.title);
|
||||
}
|
||||
li.append(` — ${[row.company, row.place].filter(Boolean).join(", ")}`);
|
||||
list.appendChild(li);
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in new issue
Block a user