mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
fix proxy mode failing for GH private packages (#137)
* fix proxy mode failing for GH private packages * skip analysis for private packages for proxy mode * introduce npmRegistryConfig and support for handling multiple parsers in future * refactor name and unexport npm config functions * rm unused function * rename & unexport npmRegistryURLParser * add e2e for malicious pkg blocked using proxy mode
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package interceptors
|
||||
|
||||
import "strings"
|
||||
|
||||
// npmRegistryConfig defines configuration for npm registry endpoints
|
||||
type npmRegistryConfig struct {
|
||||
// Hostname
|
||||
Host string
|
||||
|
||||
// Whether this registry is supported for malware analysis
|
||||
SupportedForAnalysis bool
|
||||
|
||||
// Parser for the registry
|
||||
RegistryParser npmRegistryURLParser
|
||||
}
|
||||
|
||||
// getNpmRegistryConfigForHostname returns the configuration for a hostname (with subdomain matching)
|
||||
func getNpmRegistryConfigForHostname(hostname string) *npmRegistryConfig {
|
||||
// Check exact match first
|
||||
if config, exists := npmRegistryDomains[hostname]; exists {
|
||||
return config
|
||||
}
|
||||
|
||||
// Check subdomain match: hostname could be "cdn.registry.npmjs.org" matching "registry.npmjs.org"
|
||||
for endpoint, config := range npmRegistryDomains {
|
||||
if strings.HasSuffix(hostname, "."+endpoint) {
|
||||
return config
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user