-
-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Use SafeJoin in the uploadHandler #821
Conversation
11d3ceb
to
415f238
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #821 +/- ##
==========================================
+ Coverage 16.85% 17.76% +0.91%
==========================================
Files 53 53
Lines 4082 4103 +21
==========================================
+ Hits 688 729 +41
+ Misses 3294 3270 -24
- Partials 100 104 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
👀 |
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.
LGTM, good work 🏁
// SafeJoin performs a filepath.Join of 'parent' and 'subdir' but returns an error | ||
// if the resulting path points outside of 'parent'. | ||
func SafeJoin(parent, subdir string) (string, error) { | ||
res := filepath.Join(parent, subdir) | ||
if !strings.HasSuffix(parent, string(os.PathSeparator)) { | ||
parent += string(os.PathSeparator) | ||
} | ||
if !strings.HasPrefix(res, parent) { | ||
return res, fmt.Errorf("unsafe path join: '%s' with '%s'", parent, subdir) | ||
} | ||
return res, nil | ||
} |
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.
Maybe this could be a good candidate for go-paths-helper
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.
e523731
to
3929fea
Compare
3929fea
to
139ce6b
Compare
Fixes: https://arduino.atlassian.net/browse/PNX-1543
Fixes: https://arduino.atlassian.net/browse/PNX-4130 (e523731)