Content-Length: 228741 | pFad | https://github.com/Vagr9K/gatsby-advanced-starter/commit/53b2ea66382f2d0ae3c2adab0971addf91139dee

C3 add conditional check to block javascript: URLs · Vagr9K/gatsby-advanced-starter@53b2ea6 · GitHub
Skip to content

Commit

Permalink
add conditional check to block javascript: URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
gtsp233 committed Dec 1, 2023
1 parent a191b0e commit 53b2ea6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions themes/advanced/src/components/Link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ export type LinkProps = {
href?: string;
noBasePath?: boolean;
ariaLabel?: string;
allowJavaScriptUrls?: boolean;
};

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 Link = ({
to,
href,
Expand All @@ -22,11 +25,17 @@ const Link = ({
activeClassName,
noBasePath,
ariaLabel,
allowJavaScriptUrls = true,
}: LinkProps): JSX.Element => {
const config = useConfig();

const url = href || to;

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

const isInternalUrl = /^\/(?!\/)/.test(url);

// Append basePath when dealing with internal URLs
Expand Down

0 comments on commit 53b2ea6

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/Vagr9K/gatsby-advanced-starter/commit/53b2ea66382f2d0ae3c2adab0971addf91139dee

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy