summaryrefslogtreecommitdiff
path: root/internal/federation/federatingprotocol.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-04-26 18:10:11 +0200
committerLibravatar GitHub <noreply@github.com>2022-04-26 18:10:11 +0200
commit9cf66bf29871dad6523f421ae72125d584ac4c9a (patch)
tree328b62cb9fb8374dee576a3bb0f2ec213c0e93a0 /internal/federation/federatingprotocol.go
parent[bugfix] Trim log entries to 1700 chars before they enter syslog (#493) (diff)
downloadgotosocial-9cf66bf29871dad6523f421ae72125d584ac4c9a.tar.xz
[chore] Return more useful errors from auth failure (#494)v0.3.1
* try rsa_sha256 sig algo first * return more informative errors from auth * adapt to reworked auth function
Diffstat (limited to 'internal/federation/federatingprotocol.go')
-rw-r--r--internal/federation/federatingprotocol.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/internal/federation/federatingprotocol.go b/internal/federation/federatingprotocol.go
index 789959810..7bcefc147 100644
--- a/internal/federation/federatingprotocol.go
+++ b/internal/federation/federatingprotocol.go
@@ -119,15 +119,17 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr
return nil, false, fmt.Errorf("could not fetch receiving account with username %s: %s", username, err)
}
- publicKeyOwnerURI, authenticated, err := f.AuthenticateFederatedRequest(ctx, receivingAccount.Username)
- if err != nil {
- l.Debugf("request not authenticated: %s", err)
- return ctx, false, err
- }
-
- if !authenticated {
- w.WriteHeader(http.StatusForbidden)
- return ctx, false, nil
+ publicKeyOwnerURI, errWithCode := f.AuthenticateFederatedRequest(ctx, receivingAccount.Username)
+ if errWithCode != nil {
+ switch errWithCode.Code() {
+ case http.StatusUnauthorized, http.StatusForbidden, http.StatusBadRequest:
+ // if 400, 401, or 403, obey the interface by writing the header and bailing
+ w.WriteHeader(errWithCode.Code())
+ return ctx, false, nil
+ default:
+ // if not, there's been a proper error
+ return ctx, false, err
+ }
}
// authentication has passed, so add an instance entry for this instance if it hasn't been done already