Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ inbound:
gitlab:
baseUrl: https://gitlab.example.com/api/v4
token: ...
allowCodeAccess: false # default is false, set to true to allow Semgrep to read file contents
```

Under the hood, this config adds these allowlist items:
Expand All @@ -126,6 +127,10 @@ Under the hood, this config adds these allowlist items:
- PUT `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/discussions/:discussion/notes/:note`
- PUT `https://gitlab.example.com/api/v4/projects/:project/merge_requests/:number/discussions/:discussion`

And if `allowCodeAccess` is set, additionally:

- GET `https://gitlab.example.com/api/v4/projects/:project/repository/files/:filepath`

### Bitbucket

Similarly, the `bitbucket` configuration section grants Semgrep access to leave MR comments.
Expand Down
16 changes: 14 additions & 2 deletions pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ type GitHub struct {
}

type GitLab struct {
BaseURL string `mapstructure:"baseUrl" json:"baseUrl"`
Token string `mapstructure:"token" json:"token"`
BaseURL string `mapstructure:"baseUrl" json:"baseUrl"`
Token string `mapstructure:"token" json:"token"`
AllowCodeAccess bool `mapstructure:"allowCodeAccess" json:"allowCodeAccess"`
}

type BitBucket struct {
Expand Down Expand Up @@ -455,6 +456,17 @@ func LoadConfig(configFiles []string, deploymentId int) (*Config, error) {
SetRequestHeaders: headers,
},
)

if config.Inbound.GitLab.AllowCodeAccess {
config.Inbound.Allowlist = append(config.Inbound.Allowlist,
// get contents of file
AllowlistItem{
URL: gitLabBaseUrl.JoinPath("/projects/:project/repository/files/:filepath").String(),
Methods: ParseHttpMethods([]string{"GET"}),
SetRequestHeaders: headers,
},
)
}
}

if config.Inbound.BitBucket != nil {
Expand Down
Loading