-
Notifications
You must be signed in to change notification settings - Fork 3
fix: Address security vulnerabilities (deps + code scanning) #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e010687
fix(deps): run npm audit fix to resolve high-severity dependency vuln…
lupita-hom c9fde19
fix(security): prevent NoSQL injection and ReDoS in server controller…
lupita-hom 85c0ada
fix(security): sanitize user-controlled values before logging to prev…
lupita-hom d0982a4
fix(security): resolve remaining CodeQL alerts
lupita-hom 02af3ca
fix(security): address final 6 CodeQL alerts
lupita-hom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,12 +28,15 @@ export const requireAdminToken = (req, res, next) => { | |
| } | ||
|
|
||
| // Use constant-time comparison to prevent timing attacks. | ||
| // Hash both tokens to a fixed length (SHA-256) first to eliminate length-based timing leaks. | ||
| // Pad both values to equal length so timingSafeEqual works without hashing. | ||
| try { | ||
| const adminHash = crypto.createHash('sha256').update(adminToken).digest(); | ||
| const providedHash = crypto.createHash('sha256').update(provided).digest(); | ||
| const maxLen = Math.max(adminToken.length, provided.length); | ||
| const adminBuf = Buffer.alloc(maxLen); | ||
| const providedBuf = Buffer.alloc(maxLen); | ||
| Buffer.from(adminToken).copy(adminBuf); | ||
| Buffer.from(provided).copy(providedBuf); | ||
|
|
||
| if (!crypto.timingSafeEqual(adminHash, providedHash)) { | ||
| if (adminToken.length !== provided.length || !crypto.timingSafeEqual(adminBuf, providedBuf)) { | ||
| return res.status(401).json({ error: 'Unauthorized: valid admin token required.' }); | ||
| } | ||
| } catch (err) { | ||
|
|
@@ -125,18 +128,29 @@ export const getAllWorkflowRuns = async (req, res) => { | |
| } | ||
| }; | ||
|
|
||
| // Validates that a repo path matches the expected owner/repo format. | ||
| // Prevents NoSQL injection by rejecting paths with MongoDB operator characters. | ||
| const REPO_PATH_RE = /^[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+$/; | ||
|
|
||
| export const getRepoWorkflowRuns = async (req, res) => { | ||
| try { | ||
| const repoPath = req.params[0]; | ||
| const { workflowName } = req.query; // Get workflowName from query params | ||
| // Ensure workflowName is a plain string — qs can parse ?workflowName[$ne]=x into an | ||
| // object, which would be passed directly into a MongoDB query (NoSQL injection). | ||
| const workflowName = typeof req.query.workflowName === 'string' ? req.query.workflowName : null; | ||
|
|
||
| if (!repoPath) { | ||
| return errorResponse(res, 'Repository name is required', 400); | ||
| } | ||
|
|
||
| // Validate repoPath to prevent NoSQL injection — only allow owner/repo format | ||
| if (!REPO_PATH_RE.test(repoPath)) { | ||
| return errorResponse(res, 'Invalid repository path format', 400); | ||
| } | ||
|
|
||
| // First get the repository document to get all workflows | ||
| const repoDoc = await WorkflowRun.findOne({ 'repository.fullName': repoPath }); | ||
|
|
||
| if (!repoDoc) { | ||
| return successResponse(res, { | ||
| data: [], | ||
|
|
@@ -293,6 +307,11 @@ export const syncRepositoryWorkflowRuns = async (req, res) => { | |
| return errorResponse(res, 'Repository name is required', 400); | ||
| } | ||
|
|
||
| // Validate repoPath to prevent NoSQL injection — only allow owner/repo format | ||
| if (!REPO_PATH_RE.test(repoPath)) { | ||
| return errorResponse(res, 'Invalid repository path format', 400); | ||
| } | ||
|
|
||
| const workflowRuns = await workflowService.syncRepositoryWorkflowRuns(repoPath); | ||
|
|
||
| // After sync is complete, emit updates for each workflow run | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Check warning
Code scanning / CodeQL
Log injection Medium
Copilot Autofix
AI 1 day ago
In general, to fix log injection you should ensure any user-controlled value is normalized before being logged: strip or replace newline and carriage-return characters (and often other non-printable control characters), and clearly separate user data from static log text. For text logs, removing line breaks is typically sufficient; for HTML logs, HTML-encode.
In this file, the best fix with minimal behavioral change is to (1) make the sanitization function clearly focused on removing CR/LF (and, optionally, other control chars) and (2) apply it to all logged header-derived values. The code already does (2); we only need to adjust (1) to a simpler, recommendation-aligned implementation that static analysis tools are more likely to recognize. Specifically, in
server/server.jsaround lines 107–113, replace the currentsanitizedefinition that uses a broad control-character regex with a simpler one that explicitly strips\rand\n(and, if desired, a small, explicit additional set like\t). Leave the subsequentconsole.logcalls as-is since they already usesanitize(...).Concretely:
server/server.js, update thesanitizehelper inside the/api/webhooks/githubhandler to:null/undefined).\rand\nwith spaces (or remove them).