-
Notifications
You must be signed in to change notification settings - Fork 32
Update maven flexpack issues #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
924b474 to
7b56026
Compare
d0b405d to
8862459
Compare
8862459 to
ba7bb40
Compare
ba7bb40 to
9236238
Compare
| defer searchReader.Close() | ||
|
|
||
| // Filter to only artifacts modified in the last 2 minutes (just deployed) | ||
| cutoffTime := time.Now().Add(-2 * time.Minute) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this required? isnt the artifact name enough to filter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why I added this was, if we deploy multiple times on a specific repo for same project it accumulates the artifacts, not overwrite. And wildcard matches ALL snapshots ever deployed.
With time filtering, we only tag artifacts modified in the last 2 minutes.
We can improve this, let me know if you have any ideas on this.
| // Only include artifacts modified after cutoff | ||
| if modTime.After(cutoffTime) { | ||
| recentArtifacts = append(recentArtifacts, *item) | ||
| log.Debug(fmt.Sprintf("Including recently deployed artifact: %s (modified: %s)", item.Name, item.Modified)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seeing too many debug logs for build info construction. Would you like to have verbose level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok improving it
|
|
||
| // setMavenBuildPropertiesOnArtifacts sets build properties on deployed Maven artifacts | ||
| // Following the pattern from twine.go | ||
| func setMavenBuildPropertiesOnArtifacts(workingDir, buildName, buildNumber string, buildArgs *buildUtils.BuildConfiguration) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please consider refactoring this function, it is huge.
| // Read pom.xml to get project information | ||
| // getMavenDeployRepository determines where Maven deployed artifacts | ||
| // by parsing pom.xml distributionManagement | ||
| func getMavenDeployRepository(workingDir string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the the deployment repository is mentioned in settings.xml? is it handled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's NOT handled currently, let me check how can I implement this.
| // Handle different URL patterns | ||
| if strings.Contains(repoUrl, "/api/maven/") { | ||
| // Format: http://host/artifactory/api/maven/REPO-KEY | ||
| parts := strings.Split(repoUrl, "/api/maven/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using net/url gives better control for extracting repokey
`rawURL := "https://example.com/api/v1/users/123/profile"
// Parse the URL
u, err := url.Parse(rawURL)
if err != nil {
panic(err)
}
// Split path into segments
segments := strings.Split(strings.Trim(u.Path, "/"), "/")
// Example: extract the 4th segment (index 3)
if len(segments) > 3 {
return segments[3], nil
} else {
return "", fmt.Errof("unable to extract repo key check repotitory URL")
}`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated this.
9236238 to
f330fc2
Compare
f330fc2 to
2e8623d
Compare
📗 Scan Summary
|
|
|
||
| // parseSettingsXml reads and parses Maven settings.xml | ||
| func parseSettingsXml(settingsPath string) (*SettingsXml, error) { | ||
| data, err := os.ReadFile(settingsPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Static Application Security Testing (SAST) Vulnerability
Full description
Vulnerability Details
| Rule ID: | go-path-traversal |
Overview
Path Traversal is a type of vulnerability that allows an attacker to access
files or directories outside the intended directory structure. This can lead
to unauthorized access to sensitive files, potentially compromising the
security and confidentiality of the application or system.
Vulnerable example
func serveFile(w http.ResponseWriter, r *http.Request) {
filePath := r.URL.Query().Get("file")
http.ServeFile(w, r, filePath)
}In this example, the serveFile function serves a file based on the
file query parameter provided by the user. However, there is no validation
on the file path, allowing an attacker to traverse directories and access
files outside the intended directory structure.
Remediation
To mitigate path traversal vulnerabilities, it is essential to validate
and sanitize user input. In this example, we check if the file path starts
with the allowed directory path before serving the file.
func serveFile(w http.ResponseWriter, r *http.Request) {
filePath := r.URL.Query().Get("file")
+ if !strings.HasPrefix(filePath, "/path/to/allowed/directory/") {
+ http.Error(w, "Forbidden", http.StatusForbidden)
+ return
+ }
http.ServeFile(w, r, filePath)
}Code Flows
Vulnerable data flow analysis result
os.Args (at artifactory/commands/flexpack/maven.go line 265)
args (at artifactory/commands/flexpack/maven.go line 268)
args[i+1] (at artifactory/commands/flexpack/maven.go line 268)
return args[i+1] (at artifactory/commands/flexpack/maven.go line 268)
getSettingsXmlPath() (at artifactory/commands/flexpack/maven.go line 297)
settingsPath (at artifactory/commands/flexpack/maven.go line 302)
settingsPath (at artifactory/commands/flexpack/maven.go line 281)
settingsPath (at artifactory/commands/flexpack/maven.go line 282)
30f8b95 to
a722e09
Compare
a722e09 to
1b4a7d8
Compare


Maven FlexPack: Fix Critical XML Parsing and Artifact Collection Issues
Changes
1. Added Proper XML Parsing
PomProject,PomParent,DistributionManagement,Repositorystrings.Index()XML parsing withxml.Unmarshal()encoding/xmlIssue: String-based parsing breaks with XML comments, whitespace, namespaces, and attribute reordering.
2. Fixed Deploy Goal Detection
wasDeployCommand()to match bothdeployand*:deploypatternsIssue: Maven plugin notation
maven-deploy-plugin:deploywas not detected, causing artifact collection to be skipped.3. Fixed Artifact Collection
.jarlookup with directory scan.jar,.war,.ear,-sources.jar,-javadoc.jar,-tests.jargetPackagingType()helperIssue: Only main JAR was collected, missing sources, javadoc, tests, and other packaging types (war/ear).
4. Fixed Repository Detection
getMavenDeployRepository()now uses XML parsing<repository>and<snapshotRepository>/api/maven/patternsIssue: String parsing failed on real-world POM files, and snapshots weren't handled correctly.
5. Added Settings.xml Support for Deployment Repository
Problem: Users who define deployment repositories in settings.xml via altDeploymentRepository weren't supported - only pom.xml was checked.
Fix:
Why These Were Missed
These issues weren't caught because: