feat: output security reports as JSON when requested#138
Conversation
|
🤖 Hi @jajanet, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
Summary of ChangesHello @jajanet, 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 introduces a significant enhancement by allowing security analysis reports to be generated in JSON format. This change facilitates automated processing of security findings, making it easier to integrate with external systems for accuracy checks, standardization, and pipeline automation. The implementation includes a new parsing utility, a server-side tool to perform the conversion, and updates to the analysis workflow and user documentation to support this new functionality. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
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.
📋 Review Summary
This PR introduces a useful feature to output security reports in JSON format. The overall implementation is well-structured, with the addition of a new tool for JSON conversion, comprehensive tests, and updated documentation.
🔍 General Feedback
- One potential bug was identified in
mcp-server/src/parser.tswhere some fields were missing from theFIELD_NAMESconstant, which could lead to parsing issues. A specific comment with a suggested fix has been provided for this. - The error handling in the new
convert_report_to_jsontool is well-implemented. - The changes in the
analyze.tomlandREADME.mdare clear and correctly reflect the new functionality.
Once the suggested change is addressed, this PR will be in great shape.
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature for outputting security reports in JSON format, which will greatly improve integration with other tools. The implementation is solid, with a new tool for conversion and a new markdown parser. The addition of unit tests for the parser is also great to see.
I've found a few areas for improvement in the new parser code (mcp-server/src/parser.ts) related to maintainability and code style. Specifically, there's an incorrect JSDoc, a fragile implementation detail in how fields are parsed, and a minor style issue. Please see my detailed comments.
There was a problem hiding this comment.
This PR introduces a new feature to output security reports in JSON format. The implementation looks good overall, but I've found one potential low-severity vulnerability related to regular expression denial of service in the markdown parser.
🔍 General Feedback
- The code is well-structured and easy to understand.
- The new feature is a valuable addition to the tool.
| .replace(/\*\*/g, ''); // Remove ** markdown | ||
|
|
||
| // Split by "Vulnerability:" preceded by newline | ||
| const sections = cleanContent.split(/\n(?=#{1,6} |\s*Vulnerability:)/); |
There was a problem hiding this comment.
The markdown parser uses regular expressions to parse the security report. If the report is very large or contains certain complex patterns, these regular expressions could be slow and lead to a denial of service. The likelihood of this is low since the report is generated by the AI, but it's still a possibility.
| const sections = cleanContent.split(/\n(?=#{1,6} |\s*Vulnerability:)/); | |
| Implement safeguards such as input length limits and complexity checks on the markdown content before parsing. Consider using a more robust markdown parser library if performance becomes an issue. |
(Clone of #136, which couldn't be merged due to CLA issues that came from applying a suggestion from the GitHub bot)
This PR adds the ability to output security report results in JSON. This enables programmatic parsing for accuracy checks, standardization, and integration with SCM tools and CI/CD pipelines (e.g., GitHub Actions, Jenkins)
Example of original markdown report and corresponding JSON:
turns into
[ { "vulnerability": "Path Traversal and Command Injection", "vulnerabilityType": "Security", "severity": "Critical", "sourceLocation": { "File": "lib/router.js", "startLine": null, "endLine": null }, "sinkLocation": { "File": null, "startLine": null, "endLine": null }, "dataType": null "lineContent": "`full_path = \"\" + dispatch.static_route + (unescape(pathname));`", "description": "The `pathname` variable, derived from the URL, is not sanitized before being used to construct a file path. An attacker can use URLencoded characters like `../` to traverse the file system and access arbitrary files. This vulnerability is further escalated to command injection because the `full_path` is used in a `spawn` call, allowing an attacker to execute arbitrary commands on the system.", "recommendation": "Sanitize the `pathname` variable by removing any directory traversal characters before using it to construct a file path. Use `path.normalize()` or a similar function to resolve the path and ensure it stays within the intended directory." }, ... ]Fields are optional and written as null if not present, as the tool assumes that the
DRAFT_SECURITY_REPORT.mdfile is well-formed and has the expected fieldsThis is an initial implementation to help improve processes, and we may iterate using Vertex calls in the future. There is an upcoming PR on adding a subfield for code changes sometimes present under
recommendationas well