Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: sanitize javascript url
  • Loading branch information
gtsp233 committed Dec 1, 2023
commit c5bbc31f37f824334e0c8d582709e2320ac7a455
10 changes: 9 additions & 1 deletion src/lib/src/components/NavBar/NavBarLink/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from "react";

const isJavaScriptProtocol = /^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*\:/i

const NavBarLink = (props) => {

const {
Expand All @@ -12,9 +14,15 @@ const NavBarLink = (props) => {
onClick,
showBadge,
imgBorderRadius,
badgeBackgroundColor
badgeBackgroundColor,
allowJavaScriptUrls = true
} = props;

if (isJavaScriptProtocol.test(href) && !allowJavaScriptUrls) {
console.warn(`NavBarLink has blocked a javascript: URL as a security precaution`);
return null;
}

const renderBadge = () => {
if(showBadge > 0 || showBadge !== "") {
return <div className="app-badge"
Expand Down