From 1a0fcb5c97ce5d7cc9dac1e6fa82065dd7f8ddc8 Mon Sep 17 00:00:00 2001 From: Kent Date: Fri, 22 Sep 2023 16:41:04 -0400 Subject: [PATCH] return error if it looks like a branch hijacking Signed-off-by: Kent --- service.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service.go b/service.go index c7cf351..84e1e02 100644 --- a/service.go +++ b/service.go @@ -157,6 +157,13 @@ func (s *service) RenderManifests( if err != nil { return res, errors.Wrap(err, "error loading branch metadata") } + if oldTargetBranchMetadata == nil { + return res, errors.Errorf( + "target branch %q already exists, but does not appear to be managed by "+ + "Bookkeeper; refusing to overwrite branch contents", + rc.request.TargetBranch, + ) + } rc.target.oldBranchMetadata = *oldTargetBranchMetadata if rc.target.commit.branch, err = switchToCommitBranch(rc); err != nil {