mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-21 01:10:19 +00:00
Add more checks in migration code (#21011)
When migrating add several more important sanity checks: * SHAs must be SHAs * Refs must be valid Refs * URLs must be reasonable Signed-off-by: Andrew Thornton <art27@cantab.net> Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <matti@mdranta.net>
This commit is contained in:
parent
93a610a819
commit
e6b3be4608
24 changed files with 714 additions and 302 deletions
|
@ -63,6 +63,7 @@ type GitlabDownloader struct {
|
|||
base.NullDownloader
|
||||
ctx context.Context
|
||||
client *gitlab.Client
|
||||
baseURL string
|
||||
repoID int
|
||||
repoName string
|
||||
issueCount int64
|
||||
|
@ -125,12 +126,27 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw
|
|||
return &GitlabDownloader{
|
||||
ctx: ctx,
|
||||
client: gitlabClient,
|
||||
baseURL: baseURL,
|
||||
repoID: gr.ID,
|
||||
repoName: gr.Name,
|
||||
maxPerPage: 100,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String implements Stringer
|
||||
func (g *GitlabDownloader) String() string {
|
||||
return fmt.Sprintf("migration from gitlab server %s [%d]/%s", g.baseURL, g.repoID, g.repoName)
|
||||
}
|
||||
|
||||
// ColorFormat provides a basic color format for a GitlabDownloader
|
||||
func (g *GitlabDownloader) ColorFormat(s fmt.State) {
|
||||
if g == nil {
|
||||
log.ColorFprintf(s, "<nil: GitlabDownloader>")
|
||||
return
|
||||
}
|
||||
log.ColorFprintf(s, "migration from gitlab server %s [%d]/%s", g.baseURL, g.repoID, g.repoName)
|
||||
}
|
||||
|
||||
// SetContext set context
|
||||
func (g *GitlabDownloader) SetContext(ctx context.Context) {
|
||||
g.ctx = ctx
|
||||
|
@ -308,6 +324,11 @@ func (g *GitlabDownloader) convertGitlabRelease(rel *gitlab.Release) *base.Relea
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if !hasBaseURL(link.URL, g.baseURL) {
|
||||
WarnAndNotice("Unexpected AssetURL for assetID[%d] in %s: %s", asset.ID, g, link.URL)
|
||||
return io.NopCloser(strings.NewReader(link.URL)), nil
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", link.URL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -612,6 +633,9 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
|
|||
ForeignIndex: int64(pr.IID),
|
||||
Context: gitlabIssueContext{IsMergeRequest: true},
|
||||
})
|
||||
|
||||
// SECURITY: Ensure that the PR is safe
|
||||
_ = CheckAndEnsureSafePR(allPRs[len(allPRs)-1], g.baseURL, g)
|
||||
}
|
||||
|
||||
return allPRs, len(prs) < perPage, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue