fix: improve API endpoint regex [IDE-1896]#588
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
aaf19fb to
dbfc791
Compare
PR Reviewer Guide 🔍
|
| const SNYK_DOCS_URL = "https://docs.snyk.io" | ||
| const SNYK_DOCS_ERROR_CATALOG_PATH = "/scan-with-snyk/error-catalog" | ||
| const SNYK_DEFAULT_ALLOWED_HOST_REGEXP = `^(https?://)?api(\.(.+))?\.(snyk|snykgov)\.io$` | ||
| const SNYK_DEFAULT_ALLOWED_HOST_REGEXP = `^(https?:\/\/)?api(\.([a-z0-9._-]+))?\.(snyk|snykgov)\.io$` |
There was a problem hiding this comment.
This would prevent snyk to use private cloud unicode URLs.
It would be better to update IsValidHost with url.Parse to extract the actual host. The function could be moved to its own package to prevent possible import cycles.
There was a problem hiding this comment.
Maybe I don't want to allow people to spin up PCs with unicode characters and this is my way of discouraging their use. 😉
But in all seriousness, you are right that since this regex is only used in a few places, it may be better to scrap it entirely and have a function which parses the URL and checks the beginning subdomain is "api" and the actual domain is in a list of allowed domains (the list could be stored in a GAF configuration like this regex).
bastiandoetsch
left a comment
There was a problem hiding this comment.
Added a comment for improvement
because i can dismiss my own review!
Description
Ensure the endpoint is restricted to Snyk domains.
Checklist
make test)make generate)make lint)go get github.com/snyk/go-application-framework@YOUR_LATEST_GAF_COMMITin thecliv2directory.go.modto point to your local GAF code.go mod tidyin thecliv2directory.go.modandgo.sumchanges.