diff --git a/scanner/rails.go b/scanner/rails.go index cea5434bbc..8c97bf03d5 100644 --- a/scanner/rails.go +++ b/scanner/rails.go @@ -8,6 +8,7 @@ import ( "path" "path/filepath" "regexp" + "strconv" "strings" "github.com/pkg/errors" @@ -199,6 +200,23 @@ func configureRails(sourceDir string, config *ScannerConfig) (*SourceInfo, error } } + // extract port from Dockerfile (if present). This is primarily for thruster. + dockerfile, err := os.ReadFile("Dockerfile") + if err == nil { + re := regexp.MustCompile(`(?m)^EXPOSE\s+(?P\d+)`) + m := re.FindStringSubmatch(string(dockerfile)) + if len(m) > 0 { + port, err := strconv.Atoi(m[1]) + if err == nil { + if port < 1024 { + port += 8000 + } + + s.Port = port + } + } + } + // master.key comes with Rails apps from v5.2 onwards, but may not be present // if the app does not use Rails encrypted credentials. Rails v6 added // support for multi-environment credentials. Use the Rails searching