mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
federation/serverauth: store verified origin in request context
This commit is contained in:
parent
0a33bde865
commit
63f35754c6
2 changed files with 17 additions and 1 deletions
|
|
@ -16,6 +16,7 @@ type contextKey int
|
|||
const (
|
||||
contextKeyIPPort contextKey = iota
|
||||
contextKeyDestinationServer
|
||||
contextKeyOriginServer
|
||||
)
|
||||
|
||||
func DestinationServerNameFromRequest(r *http.Request) string {
|
||||
|
|
@ -28,3 +29,14 @@ func DestinationServerName(ctx context.Context) string {
|
|||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func OriginServerNameFromRequest(r *http.Request) string {
|
||||
return OriginServerName(r.Context())
|
||||
}
|
||||
|
||||
func OriginServerName(ctx context.Context) string {
|
||||
if origin, ok := ctx.Value(contextKeyOriginServer).(string); ok {
|
||||
return origin
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -234,7 +234,11 @@ func (sa *ServerAuth) Authenticate(r *http.Request) (*http.Request, *mautrix.Res
|
|||
return nil, &errInvalidRequestSignature
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), contextKeyDestinationServer, destination)
|
||||
ctx = log.With().Str("destination_server_name", destination).Logger().WithContext(ctx)
|
||||
ctx = context.WithValue(ctx, contextKeyOriginServer, parsed.Origin)
|
||||
ctx = log.With().
|
||||
Str("origin_server_name", parsed.Origin).
|
||||
Str("destination_server_name", destination).
|
||||
Logger().WithContext(ctx)
|
||||
modifiedReq := r.WithContext(ctx)
|
||||
modifiedReq.Body = io.NopCloser(bytes.NewReader(reqBody))
|
||||
return modifiedReq, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue