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
+16
-4
@@ -14,9 +14,10 @@
|
|||||||
* forgetting the header is the failure that looks like a server bug.
|
* 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:
|
* Beside `api` on `window`, the few helpers more than one page script uses:
|
||||||
* `count`, `cell`, `debounce`, and the company list with its affinity control
|
* `count`, `cell`, `debounce`, `safeUrl`, and the company list with its
|
||||||
* (`loadCompanies`, `companies`, `affinityControl`, `setAffinity`). One copy
|
* affinity control (`loadCompanies`, `companies`, `affinityControl`,
|
||||||
* each, since two copies of a helper is one of them being fixed.
|
* `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
|
* 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
|
* 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
|
// --------------------------------------------------------------- companies
|
||||||
|
|
||||||
/** @type {Map<string, object>} company_key -> row from /api/companies. One
|
/** @type {Map<string, object>} company_key -> row from /api/companies. One
|
||||||
@@ -170,6 +182,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(window, {
|
Object.assign(window, {
|
||||||
api, count, cell, debounce, companies, loadCompanies, affinityControl, setAffinity,
|
api, count, cell, debounce, safeUrl, companies, loadCompanies, affinityControl, setAffinity,
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { api, count, cell, companies, loadCompanies } = window;
|
const { api, count, cell, safeUrl, companies, loadCompanies } = window;
|
||||||
const $ = (sel, root = document) => root.querySelector(sel);
|
const $ = (sel, root = document) => root.querySelector(sel);
|
||||||
|
|
||||||
// `ROLEDESK_STATUSES` is set by applications.html from the same `STATUSES`
|
// `ROLEDESK_STATUSES` is set by applications.html from the same `STATUSES`
|
||||||
@@ -41,13 +41,14 @@
|
|||||||
body.replaceChildren();
|
body.replaceChildren();
|
||||||
for (const application of applications) {
|
for (const application of applications) {
|
||||||
const tr = document.createElement("tr");
|
const tr = document.createElement("tr");
|
||||||
if (application.role_uid || application.url) {
|
const externalUrl = safeUrl(application.url);
|
||||||
|
if (application.role_uid || externalUrl) {
|
||||||
const link = document.createElement("a");
|
const link = document.createElement("a");
|
||||||
link.textContent = application.role_title || "(untitled)";
|
link.textContent = application.role_title || "(untitled)";
|
||||||
if (application.role_uid) {
|
if (application.role_uid) {
|
||||||
link.href = `/roles/${encodeURIComponent(application.role_uid)}`;
|
link.href = `/roles/${encodeURIComponent(application.role_uid)}`;
|
||||||
} else {
|
} else {
|
||||||
link.href = application.url;
|
link.href = externalUrl;
|
||||||
link.target = "_blank";
|
link.target = "_blank";
|
||||||
link.rel = "noopener";
|
link.rel = "noopener";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { api, count, debounce, companies, loadCompanies, affinityControl } = window;
|
const { api, count, debounce, safeUrl, companies, loadCompanies, affinityControl } = window;
|
||||||
const $ = (sel, root = document) => root.querySelector(sel);
|
const $ = (sel, root = document) => root.querySelector(sel);
|
||||||
|
|
||||||
/** @type {object[]} the search agents, by id */
|
/** @type {object[]} the search agents, by id */
|
||||||
@@ -76,9 +76,10 @@
|
|||||||
// found where this company posts its roles.
|
// found where this company posts its roles.
|
||||||
sub.append("board not found");
|
sub.append("board not found");
|
||||||
}
|
}
|
||||||
if (company.careers_url && !company.board) {
|
const careersUrl = safeUrl(company.careers_url);
|
||||||
|
if (careersUrl && !company.board) {
|
||||||
const link = document.createElement("a");
|
const link = document.createElement("a");
|
||||||
link.href = company.careers_url;
|
link.href = careersUrl;
|
||||||
link.target = "_blank";
|
link.target = "_blank";
|
||||||
link.rel = "noopener";
|
link.rel = "noopener";
|
||||||
link.textContent = "careers page";
|
link.textContent = "careers page";
|
||||||
|
|||||||
+1
-3
@@ -47,7 +47,7 @@
|
|||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { api, esc, debounce, companies, loadCompanies, affinityControl, judgeButtons,
|
const { api, esc, debounce, safeUrl, companies, loadCompanies, affinityControl, judgeButtons,
|
||||||
loadTracked } = window;
|
loadTracked } = window;
|
||||||
const $ = (sel, root = document) => root.querySelector(sel);
|
const $ = (sel, root = document) => root.querySelector(sel);
|
||||||
|
|
||||||
@@ -110,8 +110,6 @@
|
|||||||
feedError: false, // the feed's own fetch failed; the empty state offers a retry
|
feedError: false, // the feed's own fetch failed; the empty state offers a retry
|
||||||
};
|
};
|
||||||
|
|
||||||
const safeUrl = (u) => (/^https?:\/\//i.test(u || "") ? u : "");
|
|
||||||
|
|
||||||
function ago(iso) {
|
function ago(iso) {
|
||||||
const mins = (Date.now() - new Date(iso)) / 60000;
|
const mins = (Date.now() - new Date(iso)) / 60000;
|
||||||
if (!Number.isFinite(mins)) return "";
|
if (!Number.isFinite(mins)) return "";
|
||||||
|
|||||||
+13
-7
@@ -14,7 +14,7 @@
|
|||||||
(function () {
|
(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { api, count, debounce } = window;
|
const { api, count, debounce, safeUrl } = window;
|
||||||
const $ = (sel, root = document) => root.querySelector(sel);
|
const $ = (sel, root = document) => root.querySelector(sel);
|
||||||
|
|
||||||
/** @type {{searches: object[], adzuna_key: boolean}} */
|
/** @type {{searches: object[], adzuna_key: boolean}} */
|
||||||
@@ -168,12 +168,18 @@
|
|||||||
const list = $("#search-sample");
|
const list = $("#search-sample");
|
||||||
for (const row of result.sample) {
|
for (const row of result.sample) {
|
||||||
const li = document.createElement("li");
|
const li = document.createElement("li");
|
||||||
const link = document.createElement("a");
|
const url = safeUrl(row.url);
|
||||||
link.href = row.url;
|
if (url) {
|
||||||
link.target = "_blank";
|
const link = document.createElement("a");
|
||||||
link.rel = "noopener";
|
link.href = url;
|
||||||
link.textContent = row.title;
|
link.target = "_blank";
|
||||||
li.append(link, ` — ${[row.company, row.place].filter(Boolean).join(", ")}`);
|
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);
|
list.appendChild(li);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -154,6 +154,8 @@ What was decided for roledesk and the one reason for each. The longer reasoning
|
|||||||
|
|
||||||
**Roles are a feed with a reader, not links out.** `GET /roles/{uid}` renders the feed with its reader open on that role instead of sending the reader to the board, because 29,194 of 29,196 open board roles already have a `description` averaging 6,300 characters, and a search role's short teaser is worth reading in place before deciding whether to fetch the rest.
|
**Roles are a feed with a reader, not links out.** `GET /roles/{uid}` renders the feed with its reader open on that role instead of sending the reader to the board, because 29,194 of 29,196 open board roles already have a `description` averaging 6,300 characters, and a search role's short teaser is worth reading in place before deciding whether to fetch the rest.
|
||||||
|
|
||||||
|
**Every link built from someone else's data goes through `safeUrl`.** A board, a search result, a discovered careers page and a saved application's `url` are all free text from outside the app; an `http(s)` check before it lands in an `href` is what keeps a stray `javascript:` link or a bare string typed into a field from being clickable. The reader needed this first, for `original_url`, so `safeUrl` moved to `app.js` beside the app's other shared helpers rather than staying roles.js's own; companies.js (`careers_url`), sources.js (a search sample's `url`) and applications.js (`application.url`) now use the same one.
|
||||||
|
|
||||||
**A vote moves the rank at read time and never hides.** `Store.roles` multiplies the served score by the vote (`0.5` passed, `1.2` liked, capped at 1) instead of triggering a rescore, so a vote's effect on Best match shows at once and needs no job. A vote never removes a role from the list either, because a stray tap must stay visible and a single further tap must be able to undo it.
|
**A vote moves the rank at read time and never hides.** `Store.roles` multiplies the served score by the vote (`0.5` passed, `1.2` liked, capped at 1) instead of triggering a rescore, so a vote's effect on Best match shows at once and needs no job. A vote never removes a role from the list either, because a stray tap must stay visible and a single further tap must be able to undo it.
|
||||||
|
|
||||||
**Read state is a column on `roles`, and a vote stamps it too.** `read_at` sits beside `vote`, the same shape as newsdesk's `items.read_at`, so the feed filters and counts by it directly rather than joining a side table on every page load. `set_vote` stamps it only when it is still NULL, since voting is reading in newsdesk as well; clearing a vote leaves it alone, because taking back an opinion is not un-reading the posting.
|
**Read state is a column on `roles`, and a vote stamps it too.** `read_at` sits beside `vote`, the same shape as newsdesk's `items.read_at`, so the feed filters and counts by it directly rather than joining a side table on every page load. `set_vote` stamps it only when it is still NULL, since voting is reading in newsdesk as well; clearing a vote leaves it alone, because taking back an opinion is not un-reading the posting.
|
||||||
|
|||||||
Reference in new issue
Block a user