Skip to content

Stop counting refused private addresses toward alerts - #143

Merged
jasonnorch merged 1 commit into
mainfrom
fix/blocked-address-alerting
Nov 16, 2026
Merged

jasonnorch merged 1 commit into
mainfrom
fix/blocked-address-alerting

Conversation

@jasonnorch

@jasonnorch jasonnorch commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

A lookup whose target resolves to a private or reserved address is refused by safenet (BlockedError). That error is now an expected one in IsExpectedError, so it no longer counts toward the throttle and spike alerts. This applies on every endpoint.

Nothing else about the refusal changes: no connection is made, the caller gets the same error message, and the failure is still logged at warn level with the host.

Why

It was deliberately unexpected, as a possible SSRF probe worth a look. Two problems:

  • An alert carries a lookup name and a count, never the host or the customer, so the alert could not be investigated. The log line can.
  • The trigger is a hostname the caller chooses, and names that point at private addresses are common in public DNS. A customer checking a list of subdomains would raise alerts by accident. The encryption endpoint (Add POST /v1/encryption/lookup: TLS versions, key exchange, certificate #142) made it sharper, because all three of its lookups resolve the host and fail together.

docs/decisions.md records the reversal. If the attack signal is wanted back, a counter of blocked dials in internal/metrics is the place for it, not the pager.

In this PR

  • internal/domain/errors.go: one more case in IsExpectedError.
  • Tests: the test that pinned the old behaviour is flipped (TestIsExpectedError_BlockedError_Expected), two cases added to the expected table (refused before dialing, and refused at dial time inside a net.OpError), and a service-level test that an encryption lookup against such a host records no alert.
  • docs/decisions.md, .claude/rules/lookups.md, and one internal line in the unreleased v1.3.0 changelog block.

Verification

make verify passes: gofmt, vet, golangci-lint (0 new findings), unit tests with -race, integration tests.

Assisted-by: Claude Fable 5.2

Summary by CodeRabbit

  • Bug Fixes
    • Lookups refused because a target resolves to a private or reserved address no longer contribute to alerting. The refusal message is still returned to the caller, and the event is logged with the host.

When a lookup's target resolves to a private or reserved address, safenet
refuses the connection and the lookup fails with a BlockedError. That error
was deliberately left out of IsExpectedError, so every refusal counted toward
the throttle and spike alerts, on the reasoning that it might be someone
probing for SSRF.

Two things were wrong with that. The alert names a lookup and a count, never
the host or the customer, so there was nothing in it to investigate; the log
line written for the same failure has the host. And the trigger is a hostname
the caller chooses. Names that point at private addresses are ordinary in
public DNS, so a customer checking a list of subdomains would raise alerts by
accident, and anyone could raise them on purpose. The encryption endpoint made
it sharper, because all three of its lookups resolve the host and fail
together.

The refusal itself is unchanged: nothing connects, the caller gets the same
error, and it is still logged at warn level with the host. It just no longer
reaches the alerter. docs/decisions.md records the reversal and where the
signal belongs if it is wanted back: a counter in the metrics, not the pager.

Assisted-by: Claude Fable 5.2
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change classifies safenet.BlockedError as expected. Tests check that blocked-address refusals remain visible to callers and do not generate alerts. Documentation and the changelog describe this behavior.

Changes: Blocked-address error classification

Layer / File(s) Summary
Classify blocked-address errors
internal/domain/errors.go, internal/domain/errors_test.go, internal/service/sanitize_err_test.go, docs/decisions.md, .claude/rules/lookups.md
IsExpectedError now recognizes safenet.BlockedError. Tests cover direct and wrapped errors. The decision and lookup documentation describe the classification and logging behavior.
Verify lookup response and alert behavior
internal/service/encryption_test.go, internal/handler/changelog.yaml
A service test checks that the caller receives the refusal message and that no alerts are recorded. The changelog describes the alert behavior for private- and reserved-address refusals.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 136 asks whether probe errors should be classified as findings about the target so they do not page. This change classifies safenet.BlockedError as expected and tests that the lookup records no alerts; it does not add the encryption posture endpoint.
Merge Risk: Minimal · up to 298d6

Lookups refused because a host resolves to a private or reserved address no longer feed throttle or spike alerts on the encryption lookups. The caller still receives the same error and the refusal is still logged with the host. The change is small, tested, and easy to revert, so it is ready to merge. The only caveat is that the changelog's "any endpoint" wording slightly overstates which lookup types are affected.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Stop counting refused private addresses toward alerts" matches the main change. The PR makes safenet.BlockedError an expected error in IsExpectedError, so refused lookups no longer count to…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Stop counting refused private addresses toward alerts" matches the main change. The PR makes safenet.BlockedError an expected error in IsExpectedError, so refused lookups no longer count toward throttle or spike alerts. The title is specific and concise, and it does not describe anything absent from the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c468f1a and 298d648.

Files selected for processing: 7

  • .claude/rules/lookups.md
  • docs/decisions.md
  • internal/domain/errors.go
  • internal/domain/errors_test.go
  • internal/handler/changelog.yaml
  • internal/service/encryption_test.go
  • internal/service/sanitize_err_test.go

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

@jasonnorch
jasonnorch merged commit 4a6087f into main Nov 16, 2026
3 checks passed
@jasonnorch
jasonnorch deleted the fix/blocked-address-alerting branch November 16, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant