diff options
author | Jason Song <i@wolfogre.com> | 2023-04-06 22:57:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-06 22:57:30 +0200 |
commit | d92909fa8b4427cb3e6fca4ec18487ab506e34bf (patch) | |
tree | 8c09fc83e7e57fd4e5fc5f3721d9b6b61f597322 /services/actions | |
parent | Use graceful editorconfig loader to reduce errors when loading malformed edit... (diff) | |
download | forgejo-d92909fa8b4427cb3e6fca4ec18487ab506e34bf.tar.xz forgejo-d92909fa8b4427cb3e6fca4ec18487ab506e34bf.zip |
Treat PRs with agit flow as fork PRs when triggering actions. (#23884)
There is no fork concept in agit flow, anyone with read permission can
push `refs/for/<target-branch>/<topic-branch>` to the repo. So we should
treat it as a fork pull request because it may be from an untrusted
user.
Diffstat (limited to 'services/actions')
-rw-r--r-- | services/actions/notifier_helper.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index b0e199fc6b..1c1b986a41 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -152,6 +152,21 @@ func notify(ctx context.Context, input *notifyInput) error { return fmt.Errorf("json.Marshal: %w", err) } + isForkPullRequest := false + if pr := input.PullRequest; pr != nil { + switch pr.Flow { + case issues_model.PullRequestFlowGithub: + isForkPullRequest = pr.IsFromFork() + case issues_model.PullRequestFlowAGit: + // There is no fork concept in agit flow, anyone with read permission can push refs/for/<target-branch>/<topic-branch> to the repo. + // So we can treat it as a fork pull request because it may be from an untrusted user + isForkPullRequest = true + default: + // unknown flow, assume it's a fork pull request to be safe + isForkPullRequest = true + } + } + for id, content := range workflows { run := &actions_model.ActionRun{ Title: strings.SplitN(commit.CommitMessage, "\n", 2)[0], @@ -161,7 +176,7 @@ func notify(ctx context.Context, input *notifyInput) error { TriggerUserID: input.Doer.ID, Ref: ref, CommitSHA: commit.ID.String(), - IsForkPullRequest: input.PullRequest != nil && input.PullRequest.IsFromFork(), + IsForkPullRequest: isForkPullRequest, Event: input.Event, EventPayload: string(p), Status: actions_model.StatusWaiting, |