diff --git a/public_html/script.js b/public_html/script.js index 7217613ca..5c4b738fb 100644 --- a/public_html/script.js +++ b/public_html/script.js @@ -18,6 +18,16 @@ var infoBoxOriginalPosition = {}; var customAltitudeColors = true; var myAdsbStatsSiteUrl = null; +function escapeHtml(str) { + if (str === null || str === undefined) return ''; + return String(str) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); +} + var ADSB_Enabled = true; var UAT_Enabled = false; @@ -2458,7 +2468,9 @@ function getFlightAwareIdentLink(ident, linkText) { if (!linkText) { linkText = ident; } - return " " + linkText + ""; + var safeIdent = encodeURIComponent(ident.trim()); + var safeLinkText = escapeHtml(linkText); + return " " + safeLinkText + ""; } return ""; @@ -2470,11 +2482,12 @@ function getFlightAwareModeSLink(code, ident, linkText) { linkText = "FlightAware: " + code.toUpperCase(); } - var linkHtml = "" + linkText + ""; + linkHtml += "/redirect\">" + escapeHtml(linkText) + ""; return linkHtml; } @@ -2491,10 +2504,12 @@ function getFlightAwarePhotoLink(registration) { function getAirframesModeSLink(code) { if (code !== null && code.length > 0 && code[0] !== '~' && code !== "000000") { - return "Airframes.org: " + code.toUpperCase() + ""; + var safeCode = code.replace(/[^0-9a-fA-F]/g, ''); + var displayCode = escapeHtml(code.toUpperCase()); + return "Airframes.org: " + displayCode + ""; } - return ""; + return ""; }