maragudk / maragudk/gomponents

Discussion: appetite for an opt-in helper to neutralize dangerous URL schemes in `Href`?

Open
#324 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
1.9k
Forks
59
Avg merge
1d 12h
Merged PRs (30d)
17

Description

Hi, and thanks for gomponents — the 1:1-with-HTML, minimal-by-design approach is exactly why I like it.

I'd like to gauge your appetite for a small addition before putting any work into a PR.

**Context**

gomponents HTML-escapes attribute values, which is great, but it doesn't inspect the *scheme* of a URL in `Href`. I assume that's intentional and consistent with the library's philosophy. The consequence is that a value from user or external input can still produce a dangerous link:

```go
A(Href(userInput), Text("click"))
// userInput == "javascript:alert(1)" -> clickable XSS
```

Escaping doesn't help here, since it doesn't change the navigation target.

**What I'm *not* proposing**

No change to the default behavior of `Href`. This is only about an opt-in helper.

**What I'd like your opinion on**

Would you be open to an **opt-in** helper that users explicitly choose, leaving `Href` untouched — something narrow that neutralizes dangerous schemes (collapsing them to `"#"`) and passes everything else through unchanged? For example a `SafeURL(string) string` sanitizer, and/or a `SafeHref(...)` attribute built on top of it.

I realize the core library is intentionally feature-complete, so I'm not assuming this belongs in `html`. If a core addition isn't a fit, would something under `x/` (alongside `x/slices`) be more in line with how you'd want to handle this? And if you'd rather keep URL handling entirely in user code, that's a completely reasonable answer too — I'll just keep it in my own project. I only wanted to check before writing anything. Happy to send a PR with tests if there's interest.

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing Href entry point and the x/slices organization mentioned in the issue. The work is not ready to define as done until maintainers decide whether an opt-in sanitizer belongs in the core library, under x/, or in user code; only then can implementation and tests be scoped.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
security, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.