Why You Should Never Add Query Strings to URLs - A Developer's Lesson
#Security

Why You Should Never Add Query Strings to URLs - A Developer's Lesson

Dev Reporter
4 min read

A systems programmer's journey from implementing a questionable URL tracking feature to removing it after realizing it breaks websites and violates user trust.

As developers, we often face decisions about what features to include in our projects. Sometimes we implement things because users ask for them, even when our gut tells us something's off. That's exactly what happened to Susam Pal, a systems programmer who created Wander Console, a decentralized web exploration tool similar to the old StumbleUpon.

The Wander Console allows visitors to explore interesting websites recommended by a community of personal website owners. It's a simple, self-hosted tool that connects different web communities through a network of consoles. With over 50 websites hosting it and recommending more than 1500 pages, it's become a genuinely useful tool for discovering independent web content.

The Questionable Feature

In version 0.4.0, Susam added a feature that appended a referral query string (via=) to URLs loaded through the console. So if you clicked through from susam.net/wander/ to midnight.pub, the URL would become https://midnight.pub/?via=https://susam.net/wander/. This was intended to help website owners see where their traffic was coming from.

Susam admits he wasn't entirely convinced about this feature but implemented it anyway due to popular demand. He was juggling multiple projects, including algebraic graph theory research, and didn't have time to fully consider the implications. As he puts it, "Your scientists were so preoccupied with whether or not they could that they didn't stop to think if they should."

The Breaking Point

The problems became apparent when a favorite URL of Susam's failed to load through the console: https://int10h.org/oldschool-pc-fonts/fontlist/. The console was modifying the URL by adding a query string, but the modified URL returned a 404 error.

This reveals a fundamental issue with adding query strings to existing URLs: you're creating a new URL that might point to a completely different resource or no resource at all. Even seemingly harmless query parameters can break functionality.

The Community Perspective

This is where Chris Morgan's recent blog post "I've banned query strings" comes in. Morgan writes: "I don't like people adding tracking stuff to URLs. Still less do I like people adding tracking stuff to my URLs. Did I ask? If I wanted to know I'd look at the Referer header; and if it isn't there, it's probably for a good reason. You abuse your users by adding that to the link."

This resonated with Susam, who had been feeling uneasy about the feature but couldn't articulate why. Morgan's post gave him the push he needed to remove the feature entirely.

Why Developers Care

This story matters to developers for several reasons:

  1. URL integrity matters: URLs are carefully crafted by website owners. Modifying them, even with seemingly harmless parameters, can break functionality.

  2. Trust is paramount: When users click a link, they expect to go to the exact URL they selected. Modifying it without clear consent violates that trust.

  3. Referer headers exist for a reason: If website owners want to know where traffic comes from, the Referer header provides that information without modifying URLs.

  4. Feature requests aren't always good ideas: Sometimes users ask for features that seem useful but have unintended consequences. We need to critically evaluate requests rather than blindly implementing them.

  5. Our gut feelings matter: Susam's initial reluctance was correct. We should pay attention to those nagging doubts about features we implement.

The Resolution

After reading Morgan's post, Susam removed the referral query string feature from Wander Console. The latest version (0.6.0) no longer includes this functionality. He documented the change in commit b26d77c and committed to never adding query strings to URLs again.

This is a valuable lesson for all developers who work with URLs and web navigation. As Susam concludes, "If I ever load URLs again, I'll load them exactly as the website's author intended."

Bart Simpson-style chalkboard meme saying, 'I will not add query strings to your URLs.'

The Wander Console project continues to grow, now focusing on its core functionality without the problematic tracking feature. It's a reminder that sometimes removing features is more valuable than adding them, and that respecting the web as it exists is more important than trying to track every interaction.

For those interested in exploring independent websites or setting up their own Wander Console, the project is available on Codeberg.

Comments

Loading comments...