@@ -115,6 +115,7 @@ type conflictError struct {
115115func (* conflictError ) Error () string { return "known tree size doesn't match provided old size" }
116116
117117var errUnknownLog = errors .New ("unknown log" )
118+ var errWrongBastion = errors .New ("rejected request, bad/missing bastion" )
118119var errInvalidSignature = errors .New ("invalid signature" )
119120var errBadRequest = errors .New ("invalid input" )
120121var errProof = errors .New ("bad consistency proof" )
@@ -148,7 +149,7 @@ func (w *Witness) serveAddCheckpoint(rw http.ResponseWriter, r *http.Request) {
148149 return
149150 }
150151 switch err {
151- case errUnknownLog , errInvalidSignature :
152+ case errUnknownLog , errInvalidSignature , errWrongBastion :
152153 http .Error (rw , err .Error (), http .StatusForbidden )
153154 return
154155 case errBadRequest :
@@ -206,14 +207,20 @@ func (w *Witness) processAddCheckpointRequest(body []byte, bastion string) (cosi
206207 return nil , err
207208 }
208209 if len (bastions ) > 0 {
209- // Accept requests only via these bastion.
210- if bastion == "" || ! slices .Contains (bastions , bastion ) {
211- return nil , fmt .Errorf ("rejected request with origin %q via bastion %q (wrong bastion)" , origin , bastion )
210+ // Accept requests only via these bastions.
211+ if bastion == "" {
212+ l .Debug ("rejected request not using bastion" )
213+ return nil , errWrongBastion
214+ }
215+ if ! slices .Contains (bastions , bastion ) {
216+ l .Debug ("rejected request from unexpected bastion" , "bastion" , bastion )
217+ return nil , errWrongBastion
212218 }
213219 } else {
214220 // Reject requests from log-specific bastions.
215221 if bastion != "" {
216- return nil , fmt .Errorf ("rejected request with origin %q via bastion %q (should not use bastion)" , origin , bastion )
222+ l .Debug ("rejected request that should not use a bastion" , "bastion" , bastion )
223+ return nil , errWrongBastion
217224 }
218225 }
219226 verifier , err := w .getKeys (origin )
0 commit comments