fix(providers): restrict comment editing to PAC-owned comments#2488
Conversation
Summary of ChangesHello @theakshaypant, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness and security of the comment management functionality within the Pipelines-as-Code system. By introducing a mechanism to verify comment ownership before editing, it prevents unintended modifications to comments made by external entities, thereby improving the integrity of communication on pull requests across Gitea and GitLab platforms. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to enhance security by preventing Pipelines-as-Code from editing comments it does not own across Gitea and GitLab providers, correctly verifying comment authorship. However, a high-severity vulnerability exists where both Gitea and GitLab implementations lack a nil check for the comment author object, potentially leading to a nil pointer dereference and controller panic if an author is missing. Additionally, the GitLab implementation has a type mismatch that would prevent compilation.
| if comment.Poster.ID != v.pacUserID { | ||
| v.Logger.Debugf("Skipping comment %d: created by user ID %d (%s), PAC user ID is %d", | ||
| comment.ID, comment.Poster.ID, comment.Poster.UserName, v.pacUserID) | ||
| continue | ||
| } |
There was a problem hiding this comment.
The code accesses comment.Poster.ID and comment.Poster.UserName without checking if comment.Poster is nil. This is a critical vulnerability as comment.Poster can be nil in the Gitea/Forgejo SDK (e.g., for system comments or deleted users), leading to a nil pointer dereference and a controller panic, causing a Denial of Service. A nil check is required before accessing its fields. This is especially important when verifying comment authorship by the app, as outlined in repository guidelines. Additionally, consider adding a unit test to cover scenarios where the comment's author is nil.
References
- When a GitHub App needs to find and update a comment it previously posted, it must verify that the comment was authored by the app itself before editing. This nil check is a prerequisite for safely performing such an authorship verification.
There was a problem hiding this comment.
Deleted user comments are associated with GhostUserID.
System comments are associated with ActionsUserID.
530ad59 to
e4fc636
Compare
|
/review |
pkg/provider/gitea/gitea.go
Outdated
| pacUser, _, err := v.Client().GetMyUserInfo() | ||
| if err != nil { | ||
| return fmt.Errorf("unable to fetch pipelines-as-code user: %w", err) | ||
| } |
There was a problem hiding this comment.
this would not be an accurate logging statement, since it's not he pipelines-as-code user, maybe just use user info (and for other places where this is references)
58cdfb7 to
87bafae
Compare
ff84362 to
a02074c
Compare
pkg/provider/gitea/gitea.go
Outdated
| // Only edit comments created by this PAC installation's credentials. | ||
| // Prevents accidentally modifying comments from other users/bots. | ||
| if comment.Poster.ID != v.pacUserID { | ||
| v.Logger.Debugf("Skipping comment %d: created by user ID %d, PAC user ID is %d", |
There was a problem hiding this comment.
| v.Logger.Debugf("Skipping comment %d: created by user ID %d, PAC user ID is %d", | |
| v.Logger.Debugf("comment is not created by PaC , skipping editing comment: %d, created by user: %d, PaC user: %d", |
There was a problem hiding this comment.
this comment has not been created by PAC
Add check to ensure PAC only edits comments created by its own credentials, preventing accidental modification of comments from other users or bot accounts. Jira: https://issues.redhat.com/browse/SRVKP-10857 Signed-off-by: Akshay Pant <akshay.akshaypant@gmail.com> Assisted-by: Claude Sonnet 4.5 (via Claude Code)
a02074c to
4d6d2a9
Compare
📝 Description of the Change
Add check to ensure PAC only edits comments created by its own credentials, preventing accidental modification of comments from other users or bot accounts.
👨🏻 Linked Jira
https://issues.redhat.com/browse/SRVKP-10857
🔗 Linked GitHub Issue
N/A
Fixes #
🚀 Type of Change
fix:)feat:)feat!:,fix!:)docs:)chore:)refactor:)enhance:)deps:)🧪 Testing Strategy
🤖 AI Assistance
If you have used AI assistance, please provide the following details:
Which LLM was used?
Extent of AI Assistance:
Important
If the majority of the code in this PR was generated by an AI, please add a
Co-authored-bytrailer to your commit message.For example:
Co-authored-by: Gemini gemini@google.com
Co-authored-by: ChatGPT noreply@chatgpt.com
Co-authored-by: Claude noreply@anthropic.com
Co-authored-by: Cursor noreply@cursor.com
Co-authored-by: Copilot Copilot@users.noreply.github.com
**💡You can use the script
./hack/add-llm-coauthor.shto automatically addthese co-author trailers to your commits.
✅ Submitter Checklist
fix:,feat:) matches the "Type of Change" I selected above.make testandmake lintlocally to check for and fix anyissues. For an efficient workflow, I have considered installing
pre-commit and running
pre-commit installtoautomate these checks.