* feat: improve security and prevent xss attacks * chore: fix frontend test file name location * fix: frontend test case * ci: add deployment connection
15 lines
457 B
TypeScript
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);
|
|
}
|