Skip to content

Commit 9b616f0

Browse files
committed
fix(auth): Fix improper regex during auth that can lead to SSRF
1 parent a1a6749 commit 9b616f0

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

cliv2/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/snyk/cli-extension-sbom v0.0.0-20250801142135-ae472dafa4cd
1919
github.com/snyk/container-cli v0.0.0-20250321132345-1e2e01681dd7
2020
github.com/snyk/error-catalog-golang-public v0.0.0-20250812140843-a01d75260003
21-
github.com/snyk/go-application-framework v0.0.0-20250827114158-979c983b5beb
21+
github.com/snyk/go-application-framework v0.0.0-20250828183950-34b0aa676be8
2222
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65
2323
github.com/snyk/snyk-iac-capture v0.6.5
2424
github.com/snyk/snyk-ls v0.0.0-20250826112710-2b9103023173

cliv2/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,8 @@ github.com/snyk/container-cli v0.0.0-20250321132345-1e2e01681dd7 h1:/2+2piwQtB9f
13011301
github.com/snyk/container-cli v0.0.0-20250321132345-1e2e01681dd7/go.mod h1:38w+dcAQp9eG3P5t2eNS9eG0reut10AeJjLv5lJ5lpM=
13021302
github.com/snyk/error-catalog-golang-public v0.0.0-20250812140843-a01d75260003 h1:qeXih9sVe/WvhccE3MfEgglnSVKN1xTQBcsA/N96Kzo=
13031303
github.com/snyk/error-catalog-golang-public v0.0.0-20250812140843-a01d75260003/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
1304-
github.com/snyk/go-application-framework v0.0.0-20250827114158-979c983b5beb h1:7Ul0tCIguoSCuZ1kLGj7e7Yt5YRBYRDHDMHXhLEeX20=
1305-
github.com/snyk/go-application-framework v0.0.0-20250827114158-979c983b5beb/go.mod h1:BcHDVsw0EkwisckVp8qVItO1eqI98fMrb61GCGr7ERM=
1304+
github.com/snyk/go-application-framework v0.0.0-20250828183950-34b0aa676be8 h1:TXM70Bs8vu3mNhvOIXKd2ZnT9gqL6egIW+m4WWoiYYY=
1305+
github.com/snyk/go-application-framework v0.0.0-20250828183950-34b0aa676be8/go.mod h1:BcHDVsw0EkwisckVp8qVItO1eqI98fMrb61GCGr7ERM=
13061306
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 h1:CEQuYv0Go6MEyRCD3YjLYM2u3Oxkx8GpCpFBd4rUTUk=
13071307
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
13081308
github.com/snyk/policy-engine v0.33.2 h1:ZxD6/RQ4vqUAXa64V72SsGjZ8vmnBgZNGYQxMIqctYo=

scripts/upgrade-snyk-go-dependencies.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ func getLatestCommitSHA(name string) (string, error) {
8585
}
8686

8787
func upgradeGoMod(name, commitSHA string) error {
88+
fmt.Println("🔍 Upgrading: ", name)
89+
fmt.Println("🔍 Commit SHA: ", commitSHA)
90+
8891
cmd := exec.Command("go", "get", fmt.Sprintf("github.com/snyk/%s@%s", name, commitSHA))
8992
cmd.Dir = "./cliv2"
9093
if err := cmd.Run(); err != nil {
@@ -102,13 +105,18 @@ func upgradeGoMod(name, commitSHA string) error {
102105
return nil
103106
}
104107

105-
func upgradeDep(name string) error {
106-
commitSHA, err := getLatestCommitSHA(name)
107-
if err != nil {
108-
return err
108+
func upgradeDep(name string, commit string) error {
109+
var err error
110+
111+
if commit == "" {
112+
fmt.Println("🔍 No commit SHA provided, fetching latest commit...")
113+
commit, err = getLatestCommitSHA(name)
114+
if err != nil {
115+
return err
116+
}
109117
}
110118

111-
if err := upgradeGoMod(name, commitSHA); err != nil {
119+
if err := upgradeGoMod(name, commit); err != nil {
112120
return err
113121
}
114122

@@ -117,17 +125,18 @@ func upgradeDep(name string) error {
117125

118126
func main() {
119127
name := flag.String("name", "", "Repository name to download from (e.g., go-application-framework)")
128+
commit := flag.String("commit", "", "Commit SHA to upgrade to")
120129
flag.Parse()
121130

122131
if *name == "" {
123-
if err := upgradeDep("go-application-framework"); err != nil {
132+
if err := upgradeDep("go-application-framework", ""); err != nil {
124133
fmt.Printf("An error occurred: %v\n", err)
125134
}
126-
if err := upgradeDep("snyk-ls"); err != nil {
135+
if err := upgradeDep("snyk-ls", ""); err != nil {
127136
fmt.Printf("An error occurred: %v\n", err)
128137
}
129138
} else {
130-
if err := upgradeDep(*name); err != nil {
139+
if err := upgradeDep(*name, *commit); err != nil {
131140
fmt.Printf("An error occurred: %v\n", err)
132141
}
133142
}

test/jest/acceptance/auth.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ describe('Auth', () => {
122122
...env,
123123
// SNYK_API will actually be used up until the auth workflow
124124
SNYK_API: 'https://api.this.should.not.be.used.io',
125+
// override the auth host regex check, else fakeServerHost will be rejected
126+
INTERNAL_OAUTH_ALLOWED_HOSTS: '.*',
125127
},
126128
});
127129

@@ -130,6 +132,8 @@ describe('Auth', () => {
130132
const configCmd = await runSnykCLI('config get api', {
131133
env: {
132134
...env,
135+
// override the auth host regex check, else fakeServerHost will be rejected
136+
INTERNAL_OAUTH_ALLOWED_HOSTS: '.*',
133137
},
134138
});
135139
expect(configCmd.code).toEqual(0);
@@ -144,6 +148,8 @@ describe('Auth', () => {
144148
const authCmd = await runSnykCLI(`auth ${pat} -d`, {
145149
env: {
146150
...envBackup,
151+
// override the auth host regex check, else fakeServerHost will be rejected
152+
INTERNAL_OAUTH_ALLOWED_HOSTS: '.*',
147153
},
148154
});
149155

@@ -152,6 +158,8 @@ describe('Auth', () => {
152158
const configCmd = await runSnykCLI('config get api', {
153159
env: {
154160
...envBackup,
161+
// override the auth host regex check, else fakeServerHost will be rejected
162+
INTERNAL_OAUTH_ALLOWED_HOSTS: '.*',
155163
},
156164
});
157165
expect(configCmd.code).toEqual(0);

test/jest/acceptance/pat.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ describe('PAT', () => {
2121
...process.env,
2222
SNYK_TOKEN: pat,
2323
SNYK_DISABLE_ANALYTICS: '1',
24+
// override the auth host regex check, else host will be rejected
25+
INTERNAL_OAUTH_ALLOWED_HOSTS: '.*',
2426
};
2527

2628
server = fakeServer(apiPath, env.SNYK_TOKEN);

0 commit comments

Comments
 (0)