Skip to content

Commit 3571ef9

Browse files
authored
update bitbucket network config (#101)
We have been adding new features that use bitbucket APIs that are not on the allowlist yet: - get, create, update and delete namespace webhook - get and update pull request comment - get file content - update commit status
1 parent ac2e77e commit 3571ef9

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ inbound:
170170
bitbucket:
171171
baseUrl: https://bitbucket.example.com/rest/api/latest
172172
token: ...
173+
allowCodeAccess: false # default is false, set to true to allow Semgrep to read file contents
173174
```
174175

175176
Under the hood, this config adds these allowlist items:
@@ -180,7 +181,19 @@ Under the hood, this config adds these allowlist items:
180181
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/default-branch`
181182
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/:repo/pull-requests`
182183
- POST `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/pull-requests/:number/comments`
184+
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/pull-requests/:number/comments/:comment`
185+
- PUT `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/pull-requests/:number/comments/:comment`
183186
- POST `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/pull-requests/:number/blocker-comments`
187+
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/webhooks`
188+
- POST `https://bitbucket.example.com/rest/api/latest/projects/:project/webhooks`
189+
- PUT `https://bitbucket.example.com/rest/api/latest/projects/:project/webhooks/:webhook`
190+
- DELETE `https://bitbucket.example.com/rest/api/latest/projects/:project/webhooks/:webhook`
191+
192+
And if `allowCodeAccess` is set, additionally:
193+
194+
- GET `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/browse/:filepath`
195+
- POST `https://bitbucket.example.com/rest/api/latest/projects/:project/repos/:repo/commit/:commit/builds`
196+
184197

185198
### AzureDevops
186199

pkg/config.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ type GitLab struct {
220220
}
221221

222222
type BitBucket struct {
223-
BaseURL string `mapstructure:"baseUrl" json:"baseUrl"`
224-
Token string `mapstructure:"token" json:"token"`
223+
BaseURL string `mapstructure:"baseUrl" json:"baseUrl"`
224+
Token string `mapstructure:"token" json:"token"`
225+
AllowCodeAccess bool `mapstructure:"allowCodeAccess" json:"allowCodeAccess"`
225226
}
226227

227228
type AzureDevOps struct {
@@ -747,13 +748,48 @@ func LoadConfig(configFiles []string, deploymentId int) (*Config, error) {
747748
Methods: ParseHttpMethods([]string{"POST"}),
748749
SetRequestHeaders: headers,
749750
},
751+
// get and update PR comment
752+
AllowlistItem{
753+
URL: bitBucketBaseUrl.JoinPath("/projects/:project/repos/:repo/pull-requests/:number/comments/:comment").String(),
754+
Methods: ParseHttpMethods([]string{"GET", "PUT"}),
755+
SetRequestHeaders: headers,
756+
},
750757
// post blockerPR comment
751758
AllowlistItem{
752759
URL: bitBucketBaseUrl.JoinPath("/projects/:project/repos/:repo/pull-requests/:number/blocker-comments").String(),
753760
Methods: ParseHttpMethods([]string{"POST"}),
754761
SetRequestHeaders: headers,
755762
},
763+
// namespace webhooks
764+
AllowlistItem{
765+
URL: bitBucketBaseUrl.JoinPath("/projects/:project/webhooks").String(),
766+
Methods: ParseHttpMethods([]string{"GET", "POST"}),
767+
SetRequestHeaders: headers,
768+
},
769+
AllowlistItem{
770+
URL: bitBucketBaseUrl.JoinPath("/projects/:project/webhooks/:webhook").String(),
771+
Methods: ParseHttpMethods([]string{"PUT", "DELETE"}),
772+
SetRequestHeaders: headers,
773+
},
756774
)
775+
776+
if config.Inbound.BitBucket.AllowCodeAccess {
777+
// get contents of file
778+
config.Inbound.Allowlist = append(config.Inbound.Allowlist,
779+
AllowlistItem{
780+
URL: bitBucketBaseUrl.JoinPath("/projects/:project/repos/:repo/browse/:filepath").String(),
781+
Methods: ParseHttpMethods([]string{"GET"}),
782+
SetRequestHeaders: headers,
783+
},
784+
// update commit status
785+
AllowlistItem{
786+
URL: bitBucketBaseUrl.JoinPath("/projects/:project/repos/:repo/commit/:commit/builds").String(),
787+
Methods: ParseHttpMethods([]string{"POST"}),
788+
SetRequestHeaders: headers,
789+
},
790+
)
791+
792+
}
757793
}
758794

759795
if config.Inbound.AzureDevOps != nil {

0 commit comments

Comments
 (0)