-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(java): extend secure cookie rule
- Loading branch information
Showing
4 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,19 +1,30 @@ | ||
const { createInvoker, getEnvironment } = require("../../../helper.js") | ||
const { createInvoker, createNewInvoker, getEnvironment } = require("../../../helper.js") | ||
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname) | ||
|
||
describe(ruleId, () => { | ||
const invoke = createInvoker(ruleId, ruleFile, testBase) | ||
|
||
|
||
test("bad", () => { | ||
const testCase = "bad.java" | ||
expect(invoke(testCase)).toMatchSnapshot(); | ||
}) | ||
|
||
|
||
test("ok", () => { | ||
const testCase = "ok.java" | ||
expect(invoke(testCase)).toMatchSnapshot(); | ||
}) | ||
|
||
|
||
// new invoker | ||
const invokeV2 = createNewInvoker(ruleId, ruleFile, testBase) | ||
|
||
test("missing_http_only", () => { | ||
const testCase = "main.java" | ||
|
||
const results = invokeV2(testCase) | ||
|
||
expect(results.Missing).toEqual([]) | ||
expect(results.Extra).toEqual([]) | ||
}) | ||
}) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Use bearer:expected java_lang_cookie_missing_secure to flag expected findings | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.Cookie; | ||
|
||
public class Test | ||
{ | ||
public static final String COOKIE_NAME = "someCookie"; | ||
|
||
public void badCookie(HttpServletResponse res) { | ||
// bearer:expected java_lang_cookie_missing_http_only | ||
javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie(COOKIE_NAME, "cookieValue"); | ||
cookie.setSecure(false); | ||
cookie.setMaxAge(60); | ||
cookie.setHttpOnly(true); | ||
res.addCookie(cookie); | ||
} | ||
|
||
public void badCookie2(HttpServletResponse res) { | ||
// bearer:expected java_lang_cookie_missing_http_only | ||
javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie(COOKIE_NAME, "cookieValue"); | ||
cookie.setHttpOnly(true); | ||
cookie.setMaxAge(60); | ||
res.addCookie(cookie); | ||
} | ||
|
||
public void badJakartaCookie(HttpServletResponse response) { | ||
// bearer:expected java_lang_cookie_missing_http_only | ||
jakarta.servlet.http.Cookie jakartaCookie = new jakarta.servlet.http.Cookie(COOKIE_NAME, "someCookieValue"); | ||
jakartaCookie.setMaxAge(60); | ||
response.addCookie(jakartaCookie); | ||
} | ||
|
||
public void badJakartaCookie2(HttpServletResponse response) { | ||
// bearer:expected java_lang_cookie_missing_http_only | ||
jakarta.servlet.http.Cookie jakartaCookie = new jakarta.servlet.http.Cookie(COOKIE_NAME, "someCookieValue"); | ||
jakartaCookie.setSecure(false); | ||
jakartaCookie.setMaxAge(60); | ||
response.addCookie(jakartaCookie); | ||
} | ||
} | ||
|