Files
tasknote/client/src/utils/UrlUtils.ts
T
rmcamposandGitHub 80314f22d0 feat: improve security and prevent xss attacks (#30)
* feat: improve security and prevent xss attacks

* chore: fix frontend test file name location

* fix: frontend test case

* ci: add deployment connection
2026-04-16 16:49:51 -03:00

15 lines
457 B
TypeScript

/**
* Validates if a URL is safe to be used in an <a> tag.
* Only allows http, https, and # (for internal links/placeholders).
*
* @param {string | null | undefined} url The URL to validate.
* @returns {boolean} True if the URL is safe, false otherwise.
*/
export function isSafeUrl(url: string | null | undefined): boolean {
if (!url) {
return false;
}
const safeProtocolRegex = /^(https?:\/\/|#)/i;
return safeProtocolRegex.test(url);
}