Add scala random samples#67
Conversation
Added 50 randomly selected scala code samples from the security dataset.
|
⏳ I'm reviewing this pull request for security vulnerabilities and code quality issues. I'll provide an update when I'm done |
There was a problem hiding this comment.
Summary of Changes
Hello @amazon-pratik, 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!
I've added 50 randomly selected Scala code samples from a security dataset. The primary purpose of these additions is to provide a comprehensive set of examples for analysis and testing, showcasing various security-related coding patterns.
Highlights
- New Scala Samples Directory: I've added a new directory, scala/random_samples/, to house 50 randomly selected Scala code samples.
- Purpose of Samples: These samples are sourced from a security dataset and are intended for analysis and testing of security rules.
- Documentation for Samples: A README.md file has been included in the scala/ directory to provide clear documentation on the purpose and contents of these new samples.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
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 or fill out our survey to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request adds a large number of Scala code samples for security analysis. While the samples effectively demonstrate various security vulnerabilities and compliant code patterns, many of them contain code quality issues such as compilation errors (missing imports, incorrect return types), unused variables, and typos. These issues should be addressed to improve the quality and usability of the samples. I've left specific comments on the files that need attention.
| import java.io._ | ||
|
|
||
| // {fact rule=template-injection@v1.0 defects=1} | ||
| def nonCompliant(req: HttpServletRequest, resp: HttpServletResponse): Unit = { |
| @@ -0,0 +1,14 @@ | |||
| import java.security.KeyStore | |||
| @@ -0,0 +1,13 @@ | |||
| // {fact rule=use-of-insufficiently-random-values@v1.0 defects=0} | |||
| @@ -0,0 +1,10 @@ | |||
| // {fact rule=untrusted-data-in-http-session@v1.0 defects=1} | |||
| @@ -0,0 +1,23 @@ | |||
| import org.apache.velocity.VelocityContext | |||
| import org.apache.velocity.app.Velocity | |||
| import java.io._ | |||
There was a problem hiding this comment.
HttpServletRequest and HttpServletResponse are used but not imported. This will cause a compilation error. Please add import javax.servlet.http.HttpServletRequest and import javax.servlet.http.HttpServletResponse.
import java.io._
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse| class AvoidPersistentCookiesCompliant @Inject()(cc: ControllerComponents) extends AbstractController(cc) { | ||
|
|
||
| // {fact rule=avoid-persistent-cookies@v1.0 defects=0} | ||
| def compliant(res: HttpServletResponse, name: String, value: String, secure: Boolean = true, maxAge: Int = 60, httpOnly: Boolean = true): Unit = { | ||
| val cookie = new Cookie("key", "value") | ||
| // Compliant: Cookie `setSecure` method is set to true. | ||
| cookie.setSecure(true) | ||
| cookie.setMaxAge(60) | ||
| cookie.setHttpOnly(true) | ||
| res.addCookie(cookie) | ||
| } | ||
| // {/fact} | ||
|
|
||
| } No newline at end of file |
There was a problem hiding this comment.
|
|
||
| class ElInjectionCompliant { | ||
| // {fact rule=el-injection@v1.0 defects=0} | ||
| def compliant(expression: String) = { |
| val map = req.getParameterMap | ||
| val vals = req.getParameterValues("input2") | ||
| val names = req.getParameterNames | ||
| val contentType = req.getContentType | ||
| val serverName = req.getServerName |
| class CookieWithoutHttpOnlyFlagNoncompliant @Inject()(cc: ControllerComponents) extends AbstractController(cc) { | ||
|
|
||
| // {fact rule=cookie-without-http-only-flag@v1.0 defects=1} | ||
| def nonCompliant(res: HttpServletResponse, name: String, value: String, secure: Boolean = true, maxAge: Int = 60, httpOnly: Boolean = true): Unit = { | ||
| val cookie = new Cookie("key", "value") | ||
| cookie.setSecure(true) | ||
| cookie.setMaxAge(60) | ||
| // Noncompliant: Cookie `setHttpOnly` method is set to false. | ||
| cookie.setHttpOnly(false) | ||
| res.addCookie(cookie) | ||
| } | ||
| // {/fact} | ||
|
|
||
| } |
There was a problem hiding this comment.
| class CookieWithoutHttpOnlyFlagCompliant @Inject()(cc: ControllerComponents) extends AbstractController(cc) { | ||
|
|
||
| // {fact rule=cookie-without-http-only-flag@v1.0 defects=0} | ||
| def compliant(res: HttpServletResponse, name: String, value: String, secure: Boolean = true, maxAge: Int = 60, httpOnly: Boolean = true): Unit = { | ||
| val cookie = new Cookie("key", "value") | ||
| cookie.setSecure(true) | ||
| cookie.setMaxAge(60) | ||
| // Compliant: Cookie `setHttpOnly` method is set to true. | ||
| cookie.setHttpOnly(true) | ||
| res.addCookie(cookie) | ||
| } | ||
| // {/fact} | ||
|
|
||
| } |
There was a problem hiding this comment.
Added 50 randomly selected scala code samples from the security dataset.