Read form fields from the POST body only (closes #160)
All checks were successful
check / check (push) Successful in 2m54s

internal/handlers/source_management.go read the target destination
with r.FormValue, which falls back to the URL query string when the
field is absent from the body. So

    POST /source/{id}/targets?url=https://hooks.slack.com/services/T/B/S

created a working target from a value carried on the request line,
where logs, proxies, Referer headers and error trackers record it.
That is the remaining ingress path of the credential-exposure class
the render, delivery-error and log-line paths were each closed for.

Every form read in these handlers is now r.PostFormValue, so no
query-string value can populate stored configuration or be taken as a
credential. The one deliberate query read, `page` on the authenticated
pagination links, is untouched: it uses r.URL.Query().Get already.

The access log no longer carries the query on any branch, so the log
half of the report is already mitigated; the Sentry half is not. The
SDK attaches the request to every captured event and copies
r.URL.RawQuery into Request.QueryString independently of the access
log, so a BeforeSend hook clears that field before an event leaves the
process. Scheme, host, path and method stay, which is what names the
failing route.

Second barrier, for the JSON path that does not exist yet: the fields
that hold a credential are tagged json:"-" so the first handler to
marshal a model cannot serialise one. Target.Config holds the
incoming-webhook URL, APIKey.Key is a bearer token, and Setting.Value
holds the session encryption key. delivery.TargetView remains the
masking barrier for the HTML path, which is unaffected.
This commit is contained in:
2026-08-17 22:49:25 +00:00
parent 41ff16a817
commit 3925fce24a
13 changed files with 529 additions and 23 deletions

40
internal/server/sentry.go Normal file
View File

@@ -0,0 +1,40 @@
package server
import "github.com/getsentry/sentry-go"
// sentryRedactedQuery stands in for the query string on every event
// shipped to Sentry.
const sentryRedactedQuery = "(redacted)"
// scrubSentryRequest drops the query string from an event's request
// context before it leaves the process.
//
// sentryhttp attaches the whole *http.Request to the scope, and
// sentry.NewRequest copies r.URL.RawQuery verbatim into
// Request.QueryString. That path is independent of the access log: it
// is populated from the request even though the log line for the same
// request records only the route pattern or a redacted query. Any
// error or panic captured while serving a request would therefore ship
// the query string to a third-party service, and a query string is
// client-chosen text that a mistyped or hand-built request can put a
// credential into.
//
// The query is not debugging signal here. One route in the service
// reads a query parameter at all — `page`, on the authenticated
// pagination links in internal/handlers/source_management.go — and
// Request.URL still carries scheme, host and path, which is what
// identifies the failing route.
func scrubSentryRequest(
event *sentry.Event,
_ *sentry.EventHint,
) *sentry.Event {
if event == nil || event.Request == nil {
return event
}
if event.Request.QueryString != "" {
event.Request.QueryString = sentryRedactedQuery
}
return event
}