Urgent.News

What's breaking now, across thousands of outlets.

Tech

Parse the destination before deduplicating a resource link

A useful project directory needs two separate answers: where will this link navigate, and what counts as the same resource? Treating those questions as one string-replacement operation creates subtle mistakes. A substring such as agprolabs.com can appear inside an unrelated hostname. Removing every query parameter can merge two different resources. Changing the destination while counting it can…

The function resourceLink validates and processes a resource link before returning an object with an explicit rejection reason or a navigation address and identity. It requires the URL to be an absolute HTTPS address and does not infer a base URL or add a protocol. The function parses the URL, compares the hostname against approved domains, and validates the path against a blocked set.

It allows www aliases and rejects credentials and non-default ports. Query parameters are preserved, while selected administrative paths are excluded. The function returns an object with the original URL and a separate identity for reporting, stripping www, ignoring the fragment, and removing utm_ parameters. The identity is not a universal canonicalization rule, and different websites may route them differently.

The MDN URL reference documents the parsed properties used by the function. The example does not fetch pages or certify content, and it does not act as an SSRF defense or complete security boundary.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

CSS Container Style Queries: Let the Parent Set the Theme

Every design system eventually grows a modifier class problem. The card needs a dark version for the footer, a compact version for the sidebar, and a "highlighted" version for the pricing page.

  • Container style queries let parents set custom properties influencing descendants' styles.
  • @container rule with style function checks computed values of custom properties on ancestors.
  • Range queries added in 2023 enable styling based on numeric values, improving nuance.

More from Monday 12 October →