twenty icon indicating copy to clipboard operation
twenty copied to clipboard

URL Hostname from link fields shows IP address when providing ip format

Open Weiko opened this issue 9 months ago • 1 comments

Bug Description

For example if you input '300' it will show 0.0.1.44. Another example: Screenshot 2024-05-13 at 18 10 34

Expected behavior

It should probably not accept links that don't have top-level domain like .com

Technical inputs

Check getUrlHostName which is using new URL("http://300").hostname. Here 300 without tld is considered valid and is interpreted as an IP and converted back to IPv4 dotted decimal notation by URL.

Weiko avatar May 13 '24 16:05 Weiko

Disclaimer: This comment was automatically generated with AI. It can give some useful hints as to where to look for, but sometimes it can also give very inaccurate answers so takes this with a pinch of salt :). To address the issue of numeric inputs being interpreted as IP addresses in getUrlHostName, a validation step should be added to check for the presence of a top-level domain (TLD) before attempting to parse the URL. Here's a suggested implementation change in /packages/twenty-front/src/utils/url/getUrlHostName.ts:

export const getUrlHostName = (url: string) => {
  try {
    if (!/\.[a-z]{2,}$/.test(url)) {
      // If URL doesn't contain a TLD, return empty string or handle as invalid
      return '';
    }
    const absoluteUrl = getAbsoluteUrl(url);
    return new URL(absoluteUrl).hostname.replace(/^www\./i, '');
  } catch {
    return '';
  }
};

This regex checks for a period followed by at least two letters at the end of the string, which is a basic validation for a TLD presence. Adjust the regex as needed to accommodate more specific requirements or to handle edge cases.

References

/packages/twenty-front/src/utils/url/getUrlHostName.ts

Ask Greptile

greptile-apps[bot] avatar May 13 '24 16:05 greptile-apps[bot]