feat: implement token security improvements for MBA-482#66
Open
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
Open
feat: implement token security improvements for MBA-482#66devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
Conversation
- Add token redaction in pkg/log/io.go with sanitizeLogData function - Detect and redact GitHub PATs (ghp_, gho_, ghu_, ghs_, ghr_) - Redact Bearer tokens and Authorization header values - Apply sanitization in Read() and Write() methods - Remove direct URL exposure in pkg/github/actions.go - getJobLogData() now always fetches content directly - GetWorkflowRunLogs() no longer exposes signed URLs - Prevents leakage of authentication tokens in URLs - Secure environment variable handling in e2e/e2e_test.go - Add buildSecureEnvVars() helper function - Avoid token concatenation in formatted strings Fixes MBA-482 Co-Authored-By: Jia Wu <jia.wu@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Consolidate 5 separate GitHub token regex patterns into single pattern - Use table-driven approach for token sanitization patterns - Remove unused returnContent parameter from getJobLogData, handleFailedJobLogs, handleSingleJobLogs - Simplify function signatures while maintaining API compatibility Co-Authored-By: Jia Wu <jia.wu@cognition.ai>
Address SonarCloud maintainability issue by properly handling the error from OptionalParam instead of discarding it with blank identifier. Co-Authored-By: Jia Wu <jia.wu@cognition.ai>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Summary
This PR implements token security improvements to prevent credential leakage in logs and API responses, addressing Jira ticket MBA-482.
Closes: MBA-482
Changes
1. Token Redaction in Logging (
pkg/log/io.go)Added
sanitizeLogData()function that redacts sensitive tokens before logging using a table-driven approach:gh[pousr]_[a-zA-Z0-9]{36}coversghp_,gho_,ghu_,ghs_,ghr_prefixed tokens2. Remove Direct URL Exposure (
pkg/github/actions.go)GetWorkflowRunLogsandgetJobLogDatano longer returnlogs_urlin responses. Content is always fetched server-side to prevent exposure of signed URLs with embedded authentication tokens.GetWorkflowRunLogsnow returns guidance to useget_job_logsinstead of actual log URLsgetJobLogData,handleFailedJobLogs,handleSingleJobLogshad thereturnContentparameter removed entirely (content is always fetched)3. Secure Environment Variable Handling (
e2e/e2e_test.go)Refactored Docker environment variable construction via
buildSecureEnvVars()helper to use string concatenation instead offmt.Sprintfto avoid token values appearing in formatted strings.Human Review Checklist
logs_urlfrom responses is acceptable. Clients relying on this field will need to update.gh[pousr]_[a-zA-Z0-9]{36}correctly matches all 5 GitHub token typessanitizeLogData()function - consider if these should be added for this security-critical codeCI Status Note
SonarCloud quality gate is failing with "B Maintainability Rating on New Code" (required: A). Investigation shows:
GetWorkflowRunLogsRecommendation: Consider accepting the B rating for this PR or adjusting the quality gate, as the security improvements are the primary goal and the maintainability issues are largely pre-existing.
Tradeoffs
return_contentparameter inGetJobLogstool is kept for API compatibility but is no longer used internally (function signatures were simplified to remove it)GetWorkflowRunLogsnow returns guidance to useget_job_logsinstead of actual log URLsLink to Devin run: https://app.devin.ai/sessions/4868ccdc95884466af20d5971f5093d9
Requested by: Jia Wu (jia.wu@cognition.ai) (@jia-cog)