Skip to content

Commit ef8e59f

Browse files
authored
add allowCodeAccess setting for gitlab (#79)
1 parent 4ac870c commit ef8e59f

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ inbound:
113113
gitlab:
114114
baseUrl: https://gitlab.example.com/api/v4
115115
token: ...
116+
allowCodeAccess: false # default is false, set to true to allow Semgrep to read file contents
116117
```
117118

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

130+
And if `allowCodeAccess` is set, additionally:
131+
132+
- GET `https://gitlab.example.com/api/v4/projects/:project/repository/files/:filepath`
133+
129134
### Bitbucket
130135

131136
Similarly, the `bitbucket` configuration section grants Semgrep access to leave MR comments.

pkg/config.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,9 @@ type GitHub struct {
208208
}
209209

210210
type GitLab struct {
211-
BaseURL string `mapstructure:"baseUrl" json:"baseUrl"`
212-
Token string `mapstructure:"token" json:"token"`
211+
BaseURL string `mapstructure:"baseUrl" json:"baseUrl"`
212+
Token string `mapstructure:"token" json:"token"`
213+
AllowCodeAccess bool `mapstructure:"allowCodeAccess" json:"allowCodeAccess"`
213214
}
214215

215216
type BitBucket struct {
@@ -455,6 +456,17 @@ func LoadConfig(configFiles []string, deploymentId int) (*Config, error) {
455456
SetRequestHeaders: headers,
456457
},
457458
)
459+
460+
if config.Inbound.GitLab.AllowCodeAccess {
461+
config.Inbound.Allowlist = append(config.Inbound.Allowlist,
462+
// get contents of file
463+
AllowlistItem{
464+
URL: gitLabBaseUrl.JoinPath("/projects/:project/repository/files/:filepath").String(),
465+
Methods: ParseHttpMethods([]string{"GET"}),
466+
SetRequestHeaders: headers,
467+
},
468+
)
469+
}
458470
}
459471

460472
if config.Inbound.BitBucket != nil {

0 commit comments

Comments
 (0)