mirror of
https://github.com/github/codeql.git
synced 2026-06-13 08:51:20 +02:00
Compare commits
2 Commits
main
...
copilot/co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d73a911d74 | ||
|
|
de8b3360bc |
@@ -1,4 +0,0 @@
|
|||||||
---
|
|
||||||
category: fix
|
|
||||||
---
|
|
||||||
* The query `actions/pr-on-self-hosted-runner` was updated to the latest standard runner labels reducing false positive results.
|
|
||||||
@@ -2,12 +2,10 @@ import actions
|
|||||||
|
|
||||||
bindingset[runner]
|
bindingset[runner]
|
||||||
predicate isGithubHostedRunner(string runner) {
|
predicate isGithubHostedRunner(string runner) {
|
||||||
// The list of github hosted repos:
|
// list of github hosted repos: https://github.com/actions/runner-images/blob/main/README.md#available-images
|
||||||
// https://github.com/actions/runner-images/blob/main/README.md#available-images
|
runner
|
||||||
// https://docs.github.com/en/enterprise-cloud@latest/actions/how-tos/write-workflows/choose-where-workflows-run/choose-the-runner-for-a-job#standard-github-hosted-runners-for-public-repositories
|
.toLowerCase()
|
||||||
runner.toLowerCase().regexpMatch("^ubuntu-([0-9.]+|latest|slim)(-arm)?$") or
|
.regexpMatch("^(ubuntu-([0-9.]+|latest)|macos-([0-9]+|latest)(-x?large)?|windows-([0-9.]+|latest))$")
|
||||||
runner.toLowerCase().regexpMatch("^macos-([0-9]+|latest)(-x?large|-intel)?$") or
|
|
||||||
runner.toLowerCase().regexpMatch("^windows-([0-9.]+|latest)(-vs[0-9.]+)?(-arm)?$")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bindingset[runner]
|
bindingset[runner]
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
name: test
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- ubuntu-24.04
|
|
||||||
- ubuntu-24.04-arm
|
|
||||||
- ubuntu-22.04
|
|
||||||
- ubuntu-22.04-arm
|
|
||||||
- ubuntu-26.04
|
|
||||||
- ubuntu-26.04-arm
|
|
||||||
- ubuntu-slim
|
|
||||||
- macos-26
|
|
||||||
- macos-26-xlarge
|
|
||||||
- macos-26-intel
|
|
||||||
- macos-26-large
|
|
||||||
- macos-latest-large
|
|
||||||
- macos-15-large
|
|
||||||
- macos-15
|
|
||||||
- macos-15-intel
|
|
||||||
- macos-latest
|
|
||||||
- macos-15
|
|
||||||
- macos-15-xlarge
|
|
||||||
- macos-14-large
|
|
||||||
- macos-14
|
|
||||||
- macos-14-xlarge
|
|
||||||
- windows-2025-vs2026
|
|
||||||
- windows-latest
|
|
||||||
- windows-2025
|
|
||||||
- windows-2022
|
|
||||||
- windows-11
|
|
||||||
- windows-11-arm
|
|
||||||
- windows-11-vs2026-arm
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
- run: cmd
|
|
||||||
@@ -203,7 +203,7 @@ module Ast implements AstSig<Location> {
|
|||||||
final private class FinalTryStmt = CS::TryStmt;
|
final private class FinalTryStmt = CS::TryStmt;
|
||||||
|
|
||||||
class TryStmt extends FinalTryStmt {
|
class TryStmt extends FinalTryStmt {
|
||||||
AstNode getBody(int index) { index = 0 and result = this.getBlock() }
|
Stmt getBody() { result = this.getBlock() }
|
||||||
|
|
||||||
CatchClause getCatch(int index) { result = this.getCatchClause(index) }
|
CatchClause getCatch(int index) { result = this.getCatchClause(index) }
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ toolchain go1.26.4
|
|||||||
// bazel mod tidy
|
// bazel mod tidy
|
||||||
require (
|
require (
|
||||||
golang.org/x/mod v0.37.0
|
golang.org/x/mod v0.37.0
|
||||||
golang.org/x/tools v0.46.0
|
golang.org/x/tools v0.45.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/stretchr/testify v1.11.1
|
require github.com/stretchr/testify v1.11.1
|
||||||
@@ -18,6 +18,6 @@ require github.com/stretchr/testify v1.11.1
|
|||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
golang.org/x/sync v0.21.0 // indirect
|
golang.org/x/sync v0.20.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
|
|||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
|
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
|
||||||
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
|
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
|
||||||
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||||
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
golang.org/x/tools v0.46.0 h1:7jTurBkPZu4moS/Uy4OQT1M+QBlsj3wejyZwsT8Z7rk=
|
golang.org/x/tools v0.45.0 h1:18qN3FAooORvApf5XjCXgsuayZOEtXf6JK18I3+ONa8=
|
||||||
golang.org/x/tools v0.46.0/go.mod h1:FrD85F8l+NWL+9XWBSyVSHO6Ne4jutsfIFba7AWQ5Ys=
|
golang.org/x/tools v0.45.0/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Arithmetic/ConstantExpAppearsNonConstant.ql
|
Likely Bugs/Arithmetic/ConstantExpAppearsNonConstant.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -117,18 +117,15 @@ private module Ast implements AstSig<Location> {
|
|||||||
final private class FinalTryStmt = J::TryStmt;
|
final private class FinalTryStmt = J::TryStmt;
|
||||||
|
|
||||||
class TryStmt extends FinalTryStmt {
|
class TryStmt extends FinalTryStmt {
|
||||||
AstNode getBody(int index) {
|
Stmt getBody() { result = super.getBlock() }
|
||||||
result = super.getResource(index)
|
|
||||||
or
|
|
||||||
index = count(super.getAResource()) and
|
|
||||||
result = super.getBlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
CatchClause getCatch(int index) { result = super.getCatchClause(index) }
|
CatchClause getCatch(int index) { result = super.getCatchClause(index) }
|
||||||
|
|
||||||
Stmt getFinally() { result = super.getFinally() }
|
Stmt getFinally() { result = super.getFinally() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AstNode getTryInit(TryStmt try, int index) { result = try.getResource(index) }
|
||||||
|
|
||||||
final private class FinalCatchClause = J::CatchClause;
|
final private class FinalCatchClause = J::CatchClause;
|
||||||
|
|
||||||
class CatchClause extends FinalCatchClause {
|
class CatchClause extends FinalCatchClause {
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Implementation Hiding/AbstractToConcreteCollection.ql
|
Violations of Best Practice/Implementation Hiding/AbstractToConcreteCollection.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/legacy/AutoBoxing.ql
|
Violations of Best Practice/legacy/AutoBoxing.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Resource Leaks/CloseReader.ql
|
Likely Bugs/Resource Leaks/CloseReader.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Resource Leaks/CloseWriter.ql
|
Likely Bugs/Resource Leaks/CloseWriter.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Naming Conventions/ConfusingOverloading.ql
|
Violations of Best Practice/Naming Conventions/ConfusingOverloading.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -2,21 +2,21 @@ fun fn0(f: Function0<Unit>) = f()
|
|||||||
|
|
||||||
fun fn1() {
|
fun fn1() {
|
||||||
var c = true
|
var c = true
|
||||||
while (c) { // $ SPURIOUS: Alert // TODO: false positive
|
while (c) { // TODO: false positive
|
||||||
fn0 {
|
fn0 {
|
||||||
c = false
|
c = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var d = true
|
var d = true
|
||||||
while (d) { // $ Alert
|
while (d) {
|
||||||
fn0 {
|
fn0 {
|
||||||
println(d)
|
println(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val e = true
|
val e = true
|
||||||
while (e) { // $ Alert
|
while (e) {
|
||||||
fn0 {
|
fn0 {
|
||||||
println(e)
|
println(e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Termination/ConstantLoopCondition.ql
|
Likely Bugs/Termination/ConstantLoopCondition.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: DeadCode/DeadClass.ql
|
DeadCode/DeadClass.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: DeadCode/DeadMethod.ql
|
DeadCode/DeadMethod.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
| test.kt:1:1:1:31 | C1 | Unused class: C1 is not referenced within this codebase. If not used as an external API it should be removed. |
|
| test.kt:1:1:1:20 | C1 | Unused class: C1 is not referenced within this codebase. If not used as an external API it should be removed. |
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Dead Code/DeadRefTypes.ql
|
Violations of Best Practice/Dead Code/DeadRefTypes.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
private class C1 { } // $ Alert
|
private class C1 { }
|
||||||
|
|
||||||
private class C2 { }
|
private class C2 { }
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Statements/EmptyBlock.ql
|
Likely Bugs/Statements/EmptyBlock.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Implementation Hiding/ExposeRepresentation.ql
|
Violations of Best Practice/Implementation Hiding/ExposeRepresentation.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Performance/InnerClassCouldBeStatic.ql
|
Performance/InnerClassCouldBeStatic.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Comparison/MissingInstanceofInEquals.ql
|
Likely Bugs/Comparison/MissingInstanceofInEquals.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Advisory/Declarations/MissingOverrideAnnotation.ql
|
Advisory/Declarations/MissingOverrideAnnotation.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Architecture/Dependencies/MutualDependency.ql
|
Architecture/Dependencies/MutualDependency.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1 +1 @@
|
|||||||
| Test.kt:12:1:12:24 | aaaa | Class and interface names should start in uppercase. |
|
| Test.kt:12:1:12:13 | aaaa | Class and interface names should start in uppercase. |
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Advisory/Naming/NamingConventionsRefTypes.ql
|
Advisory/Naming/NamingConventionsRefTypes.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -9,4 +9,4 @@ class Foo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class aaaa {} // $ Alert
|
class aaaa {}
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Serialization/NonSerializableField.ql
|
Likely Bugs/Serialization/NonSerializableField.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Serialization/NonSerializableInnerClass.ql
|
Likely Bugs/Serialization/NonSerializableInnerClass.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Nullness/NullMaybe.ql
|
Likely Bugs/Nullness/NullMaybe.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Advisory/Statements/OneStatementPerLine.ql
|
Advisory/Statements/OneStatementPerLine.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Statements/PartiallyMaskedCatch.ql
|
Likely Bugs/Statements/PartiallyMaskedCatch.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Statements/ReturnValueIgnored.ql
|
Likely Bugs/Statements/ReturnValueIgnored.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Boolean Logic/SimplifyBoolExpr.ql
|
Violations of Best Practice/Boolean Logic/SimplifyBoolExpr.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Compatibility/JDK9/UnderscoreIdentifier.ql
|
Compatibility/JDK9/UnderscoreIdentifier.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Dead Code/UnreadLocal.ql
|
Violations of Best Practice/Dead Code/UnreadLocal.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ fun fn0(size: Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun fn1(a: Array<Int>) {
|
fun fn1(a: Array<Int>) {
|
||||||
for (e in a) { // $ Alert
|
for (e in a) {
|
||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fn2(a: Array<Int>) {
|
fun fn2(a: Array<Int>) {
|
||||||
for ((idx, e) in a.withIndex()) { // $ Alert
|
for ((idx, e) in a.withIndex()) {
|
||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ fun fn(x:Any?, y: Any?) {
|
|||||||
|
|
||||||
fun fn0(o: Any?) {
|
fun fn0(o: Any?) {
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
o?.toString() // $ Alert
|
o?.toString()
|
||||||
o.toString()
|
o.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Language Abuse/UselessNullCheck.ql
|
Language Abuse/UselessNullCheck.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: DeadCode/UselessParameter.ql
|
DeadCode/UselessParameter.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Arithmetic/WhitespaceContradictsPrecedence.ql
|
Likely Bugs/Arithmetic/WhitespaceContradictsPrecedence.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Implementation Hiding/AbstractToConcreteCollection.ql
|
Violations of Best Practice/Implementation Hiding/AbstractToConcreteCollection.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/legacy/AutoBoxing.ql
|
Violations of Best Practice/legacy/AutoBoxing.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Resource Leaks/CloseReader.ql
|
Likely Bugs/Resource Leaks/CloseReader.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Resource Leaks/CloseWriter.ql
|
Likely Bugs/Resource Leaks/CloseWriter.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Naming Conventions/ConfusingOverloading.ql
|
Violations of Best Practice/Naming Conventions/ConfusingOverloading.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -2,21 +2,21 @@ fun fn0(f: Function0<Unit>) = f()
|
|||||||
|
|
||||||
fun fn1() {
|
fun fn1() {
|
||||||
var c = true
|
var c = true
|
||||||
while (c) { // $ SPURIOUS: Alert // TODO: false positive
|
while (c) { // TODO: false positive
|
||||||
fn0 {
|
fn0 {
|
||||||
c = false
|
c = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var d = true
|
var d = true
|
||||||
while (d) { // $ Alert
|
while (d) {
|
||||||
fn0 {
|
fn0 {
|
||||||
println(d)
|
println(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val e = true
|
val e = true
|
||||||
while (e) { // $ Alert
|
while (e) {
|
||||||
fn0 {
|
fn0 {
|
||||||
println(e)
|
println(e)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Termination/ConstantLoopCondition.ql
|
Likely Bugs/Termination/ConstantLoopCondition.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: DeadCode/DeadClass.ql
|
DeadCode/DeadClass.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: DeadCode/DeadMethod.ql
|
DeadCode/DeadMethod.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
| test.kt:1:1:1:31 | C1 | Unused class: C1 is not referenced within this codebase. If not used as an external API it should be removed. |
|
| test.kt:1:1:1:20 | C1 | Unused class: C1 is not referenced within this codebase. If not used as an external API it should be removed. |
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Dead Code/DeadRefTypes.ql
|
Violations of Best Practice/Dead Code/DeadRefTypes.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
private class C1 { } // $ Alert
|
private class C1 { }
|
||||||
|
|
||||||
private class C2 { }
|
private class C2 { }
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Statements/EmptyBlock.ql
|
Likely Bugs/Statements/EmptyBlock.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Implementation Hiding/ExposeRepresentation.ql
|
Violations of Best Practice/Implementation Hiding/ExposeRepresentation.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Performance/InnerClassCouldBeStatic.ql
|
Performance/InnerClassCouldBeStatic.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Comparison/MissingInstanceofInEquals.ql
|
Likely Bugs/Comparison/MissingInstanceofInEquals.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Advisory/Declarations/MissingOverrideAnnotation.ql
|
Advisory/Declarations/MissingOverrideAnnotation.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Architecture/Dependencies/MutualDependency.ql
|
Architecture/Dependencies/MutualDependency.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1 +1 @@
|
|||||||
| Test.kt:12:1:12:24 | aaaa | Class and interface names should start in uppercase. |
|
| Test.kt:12:1:12:13 | aaaa | Class and interface names should start in uppercase. |
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Advisory/Naming/NamingConventionsRefTypes.ql
|
Advisory/Naming/NamingConventionsRefTypes.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -9,4 +9,4 @@ class Foo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class aaaa {} // $ Alert
|
class aaaa {}
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Serialization/NonSerializableField.ql
|
Likely Bugs/Serialization/NonSerializableField.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Serialization/NonSerializableInnerClass.ql
|
Likely Bugs/Serialization/NonSerializableInnerClass.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Nullness/NullMaybe.ql
|
Likely Bugs/Nullness/NullMaybe.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Advisory/Statements/OneStatementPerLine.ql
|
Advisory/Statements/OneStatementPerLine.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Statements/PartiallyMaskedCatch.ql
|
Likely Bugs/Statements/PartiallyMaskedCatch.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Statements/ReturnValueIgnored.ql
|
Likely Bugs/Statements/ReturnValueIgnored.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Boolean Logic/SimplifyBoolExpr.ql
|
Violations of Best Practice/Boolean Logic/SimplifyBoolExpr.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Compatibility/JDK9/UnderscoreIdentifier.ql
|
Compatibility/JDK9/UnderscoreIdentifier.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Violations of Best Practice/Dead Code/UnreadLocal.ql
|
Violations of Best Practice/Dead Code/UnreadLocal.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ fun fn0(size: Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun fn1(a: Array<Int>) {
|
fun fn1(a: Array<Int>) {
|
||||||
for (e in a) { // $ Alert
|
for (e in a) {
|
||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fn2(a: Array<Int>) {
|
fun fn2(a: Array<Int>) {
|
||||||
for ((idx, e) in a.withIndex()) { // $ Alert
|
for ((idx, e) in a.withIndex()) {
|
||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ fun fn(x:Any?, y: Any?) {
|
|||||||
|
|
||||||
fun fn0(o: Any?) {
|
fun fn0(o: Any?) {
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
o?.toString() // $ Alert
|
o?.toString()
|
||||||
o.toString()
|
o.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: Language Abuse/UselessNullCheck.ql
|
Language Abuse/UselessNullCheck.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
query: DeadCode/UselessParameter.ql
|
DeadCode/UselessParameter.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
query: Likely Bugs/Arithmetic/WhitespaceContradictsPrecedence.ql
|
Likely Bugs/Arithmetic/WhitespaceContradictsPrecedence.ql
|
||||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/quantum/Examples/ReusedNonce.ql
|
query: experimental/quantum/Examples/ReusedNonce.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class Test {
|
|||||||
|
|
||||||
private static byte[] getRandomWrapper1() throws Exception {
|
private static byte[] getRandomWrapper1() throws Exception {
|
||||||
byte[] val = new byte[16];
|
byte[] val = new byte[16];
|
||||||
new SecureRandom().nextBytes(val); // $ Source
|
new SecureRandom().nextBytes(val);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ public class Test {
|
|||||||
IvParameterSpec ivSpec = new IvParameterSpec(iv);
|
IvParameterSpec ivSpec = new IvParameterSpec(iv);
|
||||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||||
SecretKey key = generateAESKey();
|
SecretKey key = generateAESKey();
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); // $ Alert // BAD: Reuse of `iv` in funcB1
|
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); // BAD: Reuse of `iv` in funcB1
|
||||||
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
|
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ public class Test {
|
|||||||
IvParameterSpec ivSpec = new IvParameterSpec(iv);
|
IvParameterSpec ivSpec = new IvParameterSpec(iv);
|
||||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||||
SecretKey key = generateAESKey();
|
SecretKey key = generateAESKey();
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); // $ Alert // BAD: Reuse of `iv` in funcA1
|
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); // BAD: Reuse of `iv` in funcA1
|
||||||
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
|
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,13 +73,13 @@ public class Test {
|
|||||||
IvParameterSpec ivSpec1 = new IvParameterSpec(iv);
|
IvParameterSpec ivSpec1 = new IvParameterSpec(iv);
|
||||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||||
SecretKey key1 = generateAESKey();
|
SecretKey key1 = generateAESKey();
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, key1, ivSpec1); // $ Alert // BAD: reuse of `iv` below
|
cipher.init(Cipher.ENCRYPT_MODE, key1, ivSpec1); // BAD: reuse of `iv` below
|
||||||
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
|
byte[] ciphertext = cipher.doFinal("Simple Test Data".getBytes());
|
||||||
|
|
||||||
IvParameterSpec ivSpec2 = new IvParameterSpec(iv);
|
IvParameterSpec ivSpec2 = new IvParameterSpec(iv);
|
||||||
Cipher cipher2 = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
Cipher cipher2 = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||||
SecretKey key2 = generateAESKey();
|
SecretKey key2 = generateAESKey();
|
||||||
cipher2.init(Cipher.ENCRYPT_MODE, key2, ivSpec2); // $ Alert // BAD: Reuse of `iv` above
|
cipher2.init(Cipher.ENCRYPT_MODE, key2, ivSpec2); // BAD: Reuse of `iv` above
|
||||||
byte[] ciphertext2 = cipher2.doFinal("Simple Test Data".getBytes());
|
byte[] ciphertext2 = cipher2.doFinal("Simple Test Data".getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/Security/CWE/CWE-020/Log4jJndiInjection.ql
|
query: experimental/Security/CWE/CWE-020/Log4jJndiInjection.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -18,12 +18,12 @@ public class FilePathInjection extends Controller {
|
|||||||
|
|
||||||
// BAD: Upload file to user specified path without validation
|
// BAD: Upload file to user specified path without validation
|
||||||
public void uploadFile() throws IOException {
|
public void uploadFile() throws IOException {
|
||||||
String savePath = getPara("dir"); // $ Source
|
String savePath = getPara("dir");
|
||||||
File file = getFile("fileParam").getFile();
|
File file = getFile("fileParam").getFile();
|
||||||
String finalFilePath = BASE_PATH + savePath;
|
String finalFilePath = BASE_PATH + savePath;
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(file);
|
FileInputStream fis = new FileInputStream(file);
|
||||||
FileOutputStream fos = new FileOutputStream(finalFilePath); // $ Alert
|
FileOutputStream fos = new FileOutputStream(finalFilePath);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -61,7 +61,7 @@ public class FilePathInjection extends Controller {
|
|||||||
|
|
||||||
// BAD: Upload file to user specified path without validation through session attribute
|
// BAD: Upload file to user specified path without validation through session attribute
|
||||||
public void uploadFile3() throws IOException {
|
public void uploadFile3() throws IOException {
|
||||||
String savePath = getPara("dir"); // $ Source
|
String savePath = getPara("dir");
|
||||||
setSessionAttr("uploadDir", savePath);
|
setSessionAttr("uploadDir", savePath);
|
||||||
String sessionUploadDir = getSessionAttr("uploadDir");
|
String sessionUploadDir = getSessionAttr("uploadDir");
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class FilePathInjection extends Controller {
|
|||||||
String finalFilePath = BASE_PATH + sessionUploadDir;
|
String finalFilePath = BASE_PATH + sessionUploadDir;
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(file);
|
FileInputStream fis = new FileInputStream(file);
|
||||||
FileOutputStream fos = new FileOutputStream(finalFilePath); // $ Alert
|
FileOutputStream fos = new FileOutputStream(finalFilePath);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -84,7 +84,7 @@ public class FilePathInjection extends Controller {
|
|||||||
|
|
||||||
// BAD: Upload file to user specified path without validation through request attribute
|
// BAD: Upload file to user specified path without validation through request attribute
|
||||||
public void uploadFile4() throws IOException {
|
public void uploadFile4() throws IOException {
|
||||||
String savePath = getPara("dir"); // $ Source
|
String savePath = getPara("dir");
|
||||||
setAttr("uploadDir2", savePath);
|
setAttr("uploadDir2", savePath);
|
||||||
String requestUploadDir = getAttr("uploadDir2");
|
String requestUploadDir = getAttr("uploadDir2");
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ public class FilePathInjection extends Controller {
|
|||||||
String finalFilePath = BASE_PATH + requestUploadDir;
|
String finalFilePath = BASE_PATH + requestUploadDir;
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(file);
|
FileInputStream fis = new FileInputStream(file);
|
||||||
FileOutputStream fos = new FileOutputStream(finalFilePath); // $ Alert
|
FileOutputStream fos = new FileOutputStream(finalFilePath);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -179,7 +179,7 @@ public class FilePathInjection extends Controller {
|
|||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
try {
|
try {
|
||||||
os = resp.getOutputStream();
|
os = resp.getOutputStream();
|
||||||
fis = new FileInputStream(file); // $ Alert
|
fis = new FileInputStream(file);
|
||||||
byte fileContent[] = new byte[(int) file.length()];
|
byte fileContent[] = new byte[(int) file.length()];
|
||||||
fis.read(fileContent);
|
fis.read(fileContent);
|
||||||
os.write(fileContent);
|
os.write(fileContent);
|
||||||
@@ -202,12 +202,12 @@ public class FilePathInjection extends Controller {
|
|||||||
// BAD: Download file to user specified path without validation
|
// BAD: Download file to user specified path without validation
|
||||||
public void downloadFile() throws FileNotFoundException, IOException {
|
public void downloadFile() throws FileNotFoundException, IOException {
|
||||||
HttpServletRequest request = getRequest();
|
HttpServletRequest request = getRequest();
|
||||||
String path = request.getParameter("path"); // $ Source
|
String path = request.getParameter("path");
|
||||||
String filePath = BASE_PATH + path;
|
String filePath = BASE_PATH + path;
|
||||||
|
|
||||||
HttpServletResponse resp = getResponse();
|
HttpServletResponse resp = getResponse();
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
if (path != null && file.exists()) { // $ Alert
|
if (path != null && file.exists()) {
|
||||||
resp.setHeader("Content-type", "application/force-download");
|
resp.setHeader("Content-type", "application/force-download");
|
||||||
resp.setHeader("Content-Disposition", "inline;filename=\"" + filePath + "\"");
|
resp.setHeader("Content-Disposition", "inline;filename=\"" + filePath + "\"");
|
||||||
resp.setHeader("Content-Transfer-Encoding", "Binary");
|
resp.setHeader("Content-Transfer-Encoding", "Binary");
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/Security/CWE/CWE-073/FilePathInjection.ql
|
query: experimental/Security/CWE/CWE-073/FilePathInjection.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/Security/CWE/CWE-078/CommandInjectionRuntimeExecLocal.ql
|
query: experimental/Security/CWE/CWE-078/CommandInjectionRuntimeExecLocal.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/Security/CWE/CWE-078/ExecTainted.ql
|
query: experimental/Security/CWE/CWE-078/ExecTainted.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class JSchOSInjectionTest extends HttpServlet {
|
|||||||
String host = "sshHost";
|
String host = "sshHost";
|
||||||
String user = "user";
|
String user = "user";
|
||||||
String password = "password";
|
String password = "password";
|
||||||
String command = request.getParameter("command"); // $ Source[java/command-line-injection-experimental]
|
String command = request.getParameter("command");
|
||||||
|
|
||||||
java.util.Properties config = new java.util.Properties();
|
java.util.Properties config = new java.util.Properties();
|
||||||
config.put("StrictHostKeyChecking", "no");
|
config.put("StrictHostKeyChecking", "no");
|
||||||
@@ -24,7 +24,7 @@ public class JSchOSInjectionTest extends HttpServlet {
|
|||||||
session.connect();
|
session.connect();
|
||||||
|
|
||||||
Channel channel = session.openChannel("exec");
|
Channel channel = session.openChannel("exec");
|
||||||
((ChannelExec) channel).setCommand("ping " + command); // $ Alert[java/command-line-injection-experimental]
|
((ChannelExec) channel).setCommand("ping " + command);
|
||||||
channel.setInputStream(null);
|
channel.setInputStream(null);
|
||||||
((ChannelExec) channel).setErrStream(System.err);
|
((ChannelExec) channel).setErrStream(System.err);
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ public class JSchOSInjectionTest extends HttpServlet {
|
|||||||
String host = "sshHost";
|
String host = "sshHost";
|
||||||
String user = "user";
|
String user = "user";
|
||||||
String password = "password";
|
String password = "password";
|
||||||
String command = request.getParameter("command"); // $ Source[java/command-line-injection-experimental]
|
String command = request.getParameter("command");
|
||||||
|
|
||||||
java.util.Properties config = new java.util.Properties();
|
java.util.Properties config = new java.util.Properties();
|
||||||
config.put("StrictHostKeyChecking", "no");
|
config.put("StrictHostKeyChecking", "no");
|
||||||
@@ -50,7 +50,7 @@ public class JSchOSInjectionTest extends HttpServlet {
|
|||||||
session.connect();
|
session.connect();
|
||||||
|
|
||||||
ChannelExec channel = (ChannelExec)session.openChannel("exec");
|
ChannelExec channel = (ChannelExec)session.openChannel("exec");
|
||||||
channel.setCommand("ping " + command); // $ Alert[java/command-line-injection-experimental]
|
channel.setCommand("ping " + command);
|
||||||
channel.setInputStream(null);
|
channel.setInputStream(null);
|
||||||
channel.setErrStream(System.err);
|
channel.setErrStream(System.err);
|
||||||
|
|
||||||
|
|||||||
@@ -14,29 +14,29 @@ public class RuntimeExecTest {
|
|||||||
public static void test() {
|
public static void test() {
|
||||||
System.out.println("Command injection test");
|
System.out.println("Command injection test");
|
||||||
|
|
||||||
String script = System.getenv("SCRIPTNAME"); // $ Source[java/command-line-injection-extra-local]
|
String script = System.getenv("SCRIPTNAME");
|
||||||
|
|
||||||
if (script != null) {
|
if (script != null) {
|
||||||
try {
|
try {
|
||||||
// 1. array literal in the args
|
// 1. array literal in the args
|
||||||
Runtime.getRuntime().exec(new String[]{"/bin/sh", script}); // $ Alert[java/command-line-injection-extra-local]
|
Runtime.getRuntime().exec(new String[]{"/bin/sh", script});
|
||||||
|
|
||||||
// 2. array literal with dataflow
|
// 2. array literal with dataflow
|
||||||
String[] commandArray1 = new String[]{"/bin/sh", script};
|
String[] commandArray1 = new String[]{"/bin/sh", script};
|
||||||
Runtime.getRuntime().exec(commandArray1); // $ Alert[java/command-line-injection-extra-local]
|
Runtime.getRuntime().exec(commandArray1);
|
||||||
|
|
||||||
// 3. array assignment after it is created
|
// 3. array assignment after it is created
|
||||||
String[] commandArray2 = new String[4];
|
String[] commandArray2 = new String[4];
|
||||||
commandArray2[0] = "/bin/sh";
|
commandArray2[0] = "/bin/sh";
|
||||||
commandArray2[1] = script;
|
commandArray2[1] = script;
|
||||||
Runtime.getRuntime().exec(commandArray2); // $ Alert[java/command-line-injection-extra-local]
|
Runtime.getRuntime().exec(commandArray2);
|
||||||
|
|
||||||
// 4. Stream concatenation
|
// 4. Stream concatenation
|
||||||
Runtime.getRuntime().exec(
|
Runtime.getRuntime().exec(
|
||||||
Stream.concat( // $
|
Stream.concat(
|
||||||
Arrays.stream(new String[]{"/bin/sh"}),
|
Arrays.stream(new String[]{"/bin/sh"}),
|
||||||
Arrays.stream(new String[]{script})
|
Arrays.stream(new String[]{script})
|
||||||
).toArray(String[]::new) // $ Alert[java/command-line-injection-extra-local]
|
).toArray(String[]::new)
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/Security/CWE/CWE-089/MyBatisAnnotationSqlInjection.ql
|
query: experimental/Security/CWE/CWE-089/MyBatisAnnotationSqlInjection.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/Security/CWE/CWE-089/MyBatisMapperXmlSqlInjection.ql
|
query: experimental/Security/CWE/CWE-089/MyBatisMapperXmlSqlInjection.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -16,55 +16,55 @@ public class MybatisSqlInjection {
|
|||||||
private MybatisSqlInjectionService mybatisSqlInjectionService;
|
private MybatisSqlInjectionService mybatisSqlInjectionService;
|
||||||
|
|
||||||
@GetMapping(value = "msi1")
|
@GetMapping(value = "msi1")
|
||||||
public List<Test> bad1(@RequestParam String name) { // $ Source[java/mybatis-xml-sql-injection]
|
public List<Test> bad1(@RequestParam String name) {
|
||||||
List<Test> result = mybatisSqlInjectionService.bad1(name);
|
List<Test> result = mybatisSqlInjectionService.bad1(name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "msi2")
|
@GetMapping(value = "msi2")
|
||||||
public List<Test> bad2(@RequestParam String name) { // $ Source[java/mybatis-xml-sql-injection]
|
public List<Test> bad2(@RequestParam String name) {
|
||||||
List<Test> result = mybatisSqlInjectionService.bad2(name);
|
List<Test> result = mybatisSqlInjectionService.bad2(name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "msi3")
|
@GetMapping(value = "msi3")
|
||||||
public List<Test> bad3(@ModelAttribute Test test) { // $ Source[java/mybatis-xml-sql-injection]
|
public List<Test> bad3(@ModelAttribute Test test) {
|
||||||
List<Test> result = mybatisSqlInjectionService.bad3(test);
|
List<Test> result = mybatisSqlInjectionService.bad3(test);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "msi4", method = RequestMethod.POST, produces = "application/json")
|
@RequestMapping(value = "msi4", method = RequestMethod.POST, produces = "application/json")
|
||||||
public void bad4(@RequestBody Test test) { // $ Source[java/mybatis-xml-sql-injection]
|
public void bad4(@RequestBody Test test) {
|
||||||
mybatisSqlInjectionService.bad4(test);
|
mybatisSqlInjectionService.bad4(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "msi5", method = RequestMethod.PUT, produces = "application/json")
|
@RequestMapping(value = "msi5", method = RequestMethod.PUT, produces = "application/json")
|
||||||
public void bad5(@RequestBody Test test) { // $ Source[java/mybatis-xml-sql-injection]
|
public void bad5(@RequestBody Test test) {
|
||||||
mybatisSqlInjectionService.bad5(test);
|
mybatisSqlInjectionService.bad5(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "msi6", method = RequestMethod.POST, produces = "application/json")
|
@RequestMapping(value = "msi6", method = RequestMethod.POST, produces = "application/json")
|
||||||
public void bad6(@RequestBody Map<String, String> params) { // $ Source[java/mybatis-xml-sql-injection]
|
public void bad6(@RequestBody Map<String, String> params) {
|
||||||
mybatisSqlInjectionService.bad6(params);
|
mybatisSqlInjectionService.bad6(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "msi7", method = RequestMethod.POST, produces = "application/json")
|
@RequestMapping(value = "msi7", method = RequestMethod.POST, produces = "application/json")
|
||||||
public void bad7(@RequestBody List<String> params) { // $ Source[java/mybatis-xml-sql-injection]
|
public void bad7(@RequestBody List<String> params) {
|
||||||
mybatisSqlInjectionService.bad7(params);
|
mybatisSqlInjectionService.bad7(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "msi8", method = RequestMethod.POST, produces = "application/json")
|
@RequestMapping(value = "msi8", method = RequestMethod.POST, produces = "application/json")
|
||||||
public void bad8(@RequestBody String[] params) { // $ Source[java/mybatis-xml-sql-injection]
|
public void bad8(@RequestBody String[] params) {
|
||||||
mybatisSqlInjectionService.bad8(params);
|
mybatisSqlInjectionService.bad8(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "msi9")
|
@GetMapping(value = "msi9")
|
||||||
public void bad9(@RequestParam String name) { // $ Source[java/mybatis-annotation-sql-injection]
|
public void bad9(@RequestParam String name) {
|
||||||
mybatisSqlInjectionService.bad9(name);
|
mybatisSqlInjectionService.bad9(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "msi10")
|
@GetMapping(value = "msi10")
|
||||||
public void bad10(@RequestParam Integer id, @RequestParam String name) { // $ Source[java/mybatis-annotation-sql-injection]
|
public void bad10(@RequestParam Integer id, @RequestParam String name) {
|
||||||
mybatisSqlInjectionService.bad10(id, name);
|
mybatisSqlInjectionService.bad10(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,48 +11,48 @@ public class MybatisSqlInjectionService {
|
|||||||
private SqlInjectionMapper sqlInjectionMapper;
|
private SqlInjectionMapper sqlInjectionMapper;
|
||||||
|
|
||||||
public List<Test> bad1(String name) {
|
public List<Test> bad1(String name) {
|
||||||
List<Test> result = sqlInjectionMapper.bad1(name); // $ Alert[java/mybatis-xml-sql-injection]
|
List<Test> result = sqlInjectionMapper.bad1(name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Test> bad2(String name) {
|
public List<Test> bad2(String name) {
|
||||||
List<Test> result = sqlInjectionMapper.bad2(name); // $ Alert[java/mybatis-xml-sql-injection]
|
List<Test> result = sqlInjectionMapper.bad2(name);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Test> bad3(Test test) {
|
public List<Test> bad3(Test test) {
|
||||||
List<Test> result = sqlInjectionMapper.bad3(test); // $ Alert[java/mybatis-xml-sql-injection]
|
List<Test> result = sqlInjectionMapper.bad3(test);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bad4(Test test) {
|
public void bad4(Test test) {
|
||||||
sqlInjectionMapper.bad4(test); // $ Alert[java/mybatis-xml-sql-injection]
|
sqlInjectionMapper.bad4(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bad5(Test test) {
|
public void bad5(Test test) {
|
||||||
sqlInjectionMapper.bad5(test); // $ Alert[java/mybatis-xml-sql-injection]
|
sqlInjectionMapper.bad5(test);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bad6(Map<String, String> params) {
|
public void bad6(Map<String, String> params) {
|
||||||
sqlInjectionMapper.bad6(params); // $ Alert[java/mybatis-xml-sql-injection]
|
sqlInjectionMapper.bad6(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bad7(List<String> params) {
|
public void bad7(List<String> params) {
|
||||||
sqlInjectionMapper.bad7(params); // $ Alert[java/mybatis-xml-sql-injection]
|
sqlInjectionMapper.bad7(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bad8(String[] params) {
|
public void bad8(String[] params) {
|
||||||
sqlInjectionMapper.bad8(params); // $ Alert[java/mybatis-xml-sql-injection]
|
sqlInjectionMapper.bad8(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bad9(String name) {
|
public void bad9(String name) {
|
||||||
HashMap hashMap = new HashMap();
|
HashMap hashMap = new HashMap();
|
||||||
hashMap.put("name", name);
|
hashMap.put("name", name);
|
||||||
sqlInjectionMapper.bad9(hashMap); // $ Alert[java/mybatis-annotation-sql-injection]
|
sqlInjectionMapper.bad9(hashMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bad10(Integer id, String name) {
|
public void bad10(Integer id, String name) {
|
||||||
sqlInjectionMapper.bad10(id, name); // $ Alert[java/mybatis-annotation-sql-injection]
|
sqlInjectionMapper.bad10(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Test> good1(Integer id) {
|
public List<Test> good1(Integer id) {
|
||||||
|
|||||||
@@ -10,24 +10,24 @@ public class BeanShellInjection {
|
|||||||
|
|
||||||
@GetMapping(value = "bad1")
|
@GetMapping(value = "bad1")
|
||||||
public void bad1(HttpServletRequest request) {
|
public void bad1(HttpServletRequest request) {
|
||||||
String code = request.getParameter("code"); // $ Source[java/beanshell-injection]
|
String code = request.getParameter("code");
|
||||||
BshScriptEvaluator evaluator = new BshScriptEvaluator();
|
BshScriptEvaluator evaluator = new BshScriptEvaluator();
|
||||||
evaluator.evaluate(new StaticScriptSource(code)); // $ Alert[java/beanshell-injection] //bad
|
evaluator.evaluate(new StaticScriptSource(code)); //bad
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "bad2")
|
@GetMapping(value = "bad2")
|
||||||
public void bad2(HttpServletRequest request) throws Exception {
|
public void bad2(HttpServletRequest request) throws Exception {
|
||||||
String code = request.getParameter("code"); // $ Source[java/beanshell-injection]
|
String code = request.getParameter("code");
|
||||||
Interpreter interpreter = new Interpreter();
|
Interpreter interpreter = new Interpreter();
|
||||||
interpreter.eval(code); // $ Alert[java/beanshell-injection] //bad
|
interpreter.eval(code); //bad
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "bad3")
|
@GetMapping(value = "bad3")
|
||||||
public void bad3(HttpServletRequest request) {
|
public void bad3(HttpServletRequest request) {
|
||||||
String code = request.getParameter("code"); // $ Source[java/beanshell-injection]
|
String code = request.getParameter("code");
|
||||||
StaticScriptSource staticScriptSource = new StaticScriptSource("test");
|
StaticScriptSource staticScriptSource = new StaticScriptSource("test");
|
||||||
staticScriptSource.setScript(code);
|
staticScriptSource.setScript(code);
|
||||||
BshScriptEvaluator evaluator = new BshScriptEvaluator();
|
BshScriptEvaluator evaluator = new BshScriptEvaluator();
|
||||||
evaluator.evaluate(staticScriptSource); // $ Alert[java/beanshell-injection] //bad
|
evaluator.evaluate(staticScriptSource); //bad
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/Security/CWE/CWE-094/BeanShellInjection.ql
|
query: experimental/Security/CWE/CWE-094/BeanShellInjection.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -9,24 +9,24 @@ public class JShellInjection {
|
|||||||
|
|
||||||
@GetMapping(value = "bad1")
|
@GetMapping(value = "bad1")
|
||||||
public void bad1(HttpServletRequest request) {
|
public void bad1(HttpServletRequest request) {
|
||||||
String input = request.getParameter("code"); // $ Source[java/jshell-injection]
|
String input = request.getParameter("code");
|
||||||
JShell jShell = JShell.builder().build();
|
JShell jShell = JShell.builder().build();
|
||||||
// BAD: allow execution of arbitrary Java code
|
// BAD: allow execution of arbitrary Java code
|
||||||
jShell.eval(input); // $ Alert[java/jshell-injection]
|
jShell.eval(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "bad2")
|
@GetMapping(value = "bad2")
|
||||||
public void bad2(HttpServletRequest request) {
|
public void bad2(HttpServletRequest request) {
|
||||||
String input = request.getParameter("code"); // $ Source[java/jshell-injection]
|
String input = request.getParameter("code");
|
||||||
JShell jShell = JShell.builder().build();
|
JShell jShell = JShell.builder().build();
|
||||||
SourceCodeAnalysis sourceCodeAnalysis = jShell.sourceCodeAnalysis();
|
SourceCodeAnalysis sourceCodeAnalysis = jShell.sourceCodeAnalysis();
|
||||||
// BAD: allow execution of arbitrary Java code
|
// BAD: allow execution of arbitrary Java code
|
||||||
sourceCodeAnalysis.wrappers(input); // $ Alert[java/jshell-injection]
|
sourceCodeAnalysis.wrappers(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "bad3")
|
@GetMapping(value = "bad3")
|
||||||
public void bad3(HttpServletRequest request) {
|
public void bad3(HttpServletRequest request) {
|
||||||
String input = request.getParameter("code"); // $ Source[java/jshell-injection]
|
String input = request.getParameter("code");
|
||||||
JShell jShell = JShell.builder().build();
|
JShell jShell = JShell.builder().build();
|
||||||
SourceCodeAnalysis.CompletionInfo info;
|
SourceCodeAnalysis.CompletionInfo info;
|
||||||
SourceCodeAnalysis sca = jShell.sourceCodeAnalysis();
|
SourceCodeAnalysis sca = jShell.sourceCodeAnalysis();
|
||||||
@@ -34,7 +34,7 @@ public class JShellInjection {
|
|||||||
info.completeness().isComplete();
|
info.completeness().isComplete();
|
||||||
info = sca.analyzeCompletion(info.remaining())) {
|
info = sca.analyzeCompletion(info.remaining())) {
|
||||||
// BAD: allow execution of arbitrary Java code
|
// BAD: allow execution of arbitrary Java code
|
||||||
jShell.eval(info.source()); // $ Alert[java/jshell-injection]
|
jShell.eval(info.source());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/Security/CWE/CWE-094/JShellInjection.ql
|
query: experimental/Security/CWE/CWE-094/JShellInjection.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class JakartaExpressionInjection {
|
|||||||
try (ServerSocket serverSocket = new ServerSocket(0)) {
|
try (ServerSocket serverSocket = new ServerSocket(0)) {
|
||||||
try (Socket socket = serverSocket.accept()) {
|
try (Socket socket = serverSocket.accept()) {
|
||||||
byte[] bytes = new byte[1024];
|
byte[] bytes = new byte[1024];
|
||||||
int n = socket.getInputStream().read(bytes); // $ Source[java/javaee-expression-injection]
|
int n = socket.getInputStream().read(bytes);
|
||||||
String expression = new String(bytes, 0, n);
|
String expression = new String(bytes, 0, n);
|
||||||
action.accept(expression);
|
action.accept(expression);
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ public class JakartaExpressionInjection {
|
|||||||
private static void testWithELProcessorEval() throws IOException {
|
private static void testWithELProcessorEval() throws IOException {
|
||||||
testWithSocket(expression -> {
|
testWithSocket(expression -> {
|
||||||
ELProcessor processor = new ELProcessor();
|
ELProcessor processor = new ELProcessor();
|
||||||
processor.eval(expression); // $ Alert[java/javaee-expression-injection]
|
processor.eval(expression);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public class JakartaExpressionInjection {
|
|||||||
private static void testWithELProcessorGetValue() throws IOException {
|
private static void testWithELProcessorGetValue() throws IOException {
|
||||||
testWithSocket(expression -> {
|
testWithSocket(expression -> {
|
||||||
ELProcessor processor = new ELProcessor();
|
ELProcessor processor = new ELProcessor();
|
||||||
processor.getValue(expression, Object.class); // $ Alert[java/javaee-expression-injection]
|
processor.getValue(expression, Object.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public class JakartaExpressionInjection {
|
|||||||
StandardELContext context = new StandardELContext(factory);
|
StandardELContext context = new StandardELContext(factory);
|
||||||
ValueExpression valueExpression = factory.createValueExpression(context, expression, Object.class);
|
ValueExpression valueExpression = factory.createValueExpression(context, expression, Object.class);
|
||||||
LambdaExpression lambdaExpression = new LambdaExpression(new ArrayList<>(), valueExpression);
|
LambdaExpression lambdaExpression = new LambdaExpression(new ArrayList<>(), valueExpression);
|
||||||
lambdaExpression.invoke(context, new Object[0]); // $ Alert[java/javaee-expression-injection]
|
lambdaExpression.invoke(context, new Object[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ public class JakartaExpressionInjection {
|
|||||||
private static void testWithELProcessorSetValue() throws IOException {
|
private static void testWithELProcessorSetValue() throws IOException {
|
||||||
testWithSocket(expression -> {
|
testWithSocket(expression -> {
|
||||||
ELProcessor processor = new ELProcessor();
|
ELProcessor processor = new ELProcessor();
|
||||||
processor.setValue(expression, new Object()); // $ Alert[java/javaee-expression-injection]
|
processor.setValue(expression, new Object());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class JakartaExpressionInjection {
|
|||||||
private static void testWithELProcessorSetVariable() throws IOException {
|
private static void testWithELProcessorSetVariable() throws IOException {
|
||||||
testWithSocket(expression -> {
|
testWithSocket(expression -> {
|
||||||
ELProcessor processor = new ELProcessor();
|
ELProcessor processor = new ELProcessor();
|
||||||
processor.setVariable("test", expression); // $ Alert[java/javaee-expression-injection]
|
processor.setVariable("test", expression);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class JakartaExpressionInjection {
|
|||||||
ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl();
|
ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl();
|
||||||
ELContext context = new de.odysseus.el.util.SimpleContext();
|
ELContext context = new de.odysseus.el.util.SimpleContext();
|
||||||
ValueExpression e = factory.createValueExpression(context, expression, Object.class);
|
ValueExpression e = factory.createValueExpression(context, expression, Object.class);
|
||||||
e.getValue(context); // $ Alert[java/javaee-expression-injection]
|
e.getValue(context);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ public class JakartaExpressionInjection {
|
|||||||
ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl();
|
ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl();
|
||||||
ELContext context = new de.odysseus.el.util.SimpleContext();
|
ELContext context = new de.odysseus.el.util.SimpleContext();
|
||||||
ValueExpression e = factory.createValueExpression(context, expression, Object.class);
|
ValueExpression e = factory.createValueExpression(context, expression, Object.class);
|
||||||
e.setValue(context, new Object()); // $ Alert[java/javaee-expression-injection]
|
e.setValue(context, new Object());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ public class JakartaExpressionInjection {
|
|||||||
ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl();
|
ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl();
|
||||||
ELContext context = new de.odysseus.el.util.SimpleContext();
|
ELContext context = new de.odysseus.el.util.SimpleContext();
|
||||||
MethodExpression e = factory.createMethodExpression(context, expression, Object.class, new Class[0]);
|
MethodExpression e = factory.createMethodExpression(context, expression, Object.class, new Class[0]);
|
||||||
e.invoke(context, new Object[0]); // $ Alert[java/javaee-expression-injection]
|
e.invoke(context, new Object[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/Security/CWE/CWE-094/JakartaExpressionInjection.ql
|
query: experimental/Security/CWE/CWE-094/JakartaExpressionInjection.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class JythonInjection extends HttpServlet {
|
|||||||
// BAD: allow execution of arbitrary Python code
|
// BAD: allow execution of arbitrary Python code
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
String code = request.getParameter("code"); // $ Source[java/jython-injection]
|
String code = request.getParameter("code");
|
||||||
PythonInterpreter interpreter = null;
|
PythonInterpreter interpreter = null;
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ public class JythonInjection extends HttpServlet {
|
|||||||
interpreter = new PythonInterpreter();
|
interpreter = new PythonInterpreter();
|
||||||
interpreter.setOut(out);
|
interpreter.setOut(out);
|
||||||
interpreter.setErr(out);
|
interpreter.setErr(out);
|
||||||
interpreter.exec(code); // $ Alert[java/jython-injection]
|
interpreter.exec(code);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
response.getWriter().print(out.toString());
|
response.getWriter().print(out.toString());
|
||||||
@@ -50,12 +50,12 @@ public class JythonInjection extends HttpServlet {
|
|||||||
// BAD: allow execution of arbitrary Python code
|
// BAD: allow execution of arbitrary Python code
|
||||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
String code = request.getParameter("code"); // $ Source[java/jython-injection]
|
String code = request.getParameter("code");
|
||||||
PythonInterpreter interpreter = null;
|
PythonInterpreter interpreter = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
interpreter = new PythonInterpreter();
|
interpreter = new PythonInterpreter();
|
||||||
PyObject py = interpreter.eval(code); // $ Alert[java/jython-injection]
|
PyObject py = interpreter.eval(code);
|
||||||
|
|
||||||
response.getWriter().print(py.toString());
|
response.getWriter().print(py.toString());
|
||||||
} catch(PyException ex) {
|
} catch(PyException ex) {
|
||||||
@@ -70,7 +70,7 @@ public class JythonInjection extends HttpServlet {
|
|||||||
// BAD: allow arbitrary Jython expression to run
|
// BAD: allow arbitrary Jython expression to run
|
||||||
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
String code = request.getParameter("code"); // $ Source[java/jython-injection]
|
String code = request.getParameter("code");
|
||||||
InteractiveInterpreter interpreter = null;
|
InteractiveInterpreter interpreter = null;
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ public class JythonInjection extends HttpServlet {
|
|||||||
interpreter = new InteractiveInterpreter();
|
interpreter = new InteractiveInterpreter();
|
||||||
interpreter.setOut(out);
|
interpreter.setOut(out);
|
||||||
interpreter.setErr(out);
|
interpreter.setErr(out);
|
||||||
interpreter.runsource(code); // $ Alert[java/jython-injection]
|
interpreter.runsource(code);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
response.getWriter().print(out.toString());
|
response.getWriter().print(out.toString());
|
||||||
@@ -94,7 +94,7 @@ public class JythonInjection extends HttpServlet {
|
|||||||
// BAD: load arbitrary class file to execute
|
// BAD: load arbitrary class file to execute
|
||||||
protected void doTrace(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doTrace(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
String code = request.getParameter("code"); // $ Source[java/jython-injection]
|
String code = request.getParameter("code");
|
||||||
PythonInterpreter interpreter = null;
|
PythonInterpreter interpreter = null;
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ public class JythonInjection extends HttpServlet {
|
|||||||
interpreter.setOut(out);
|
interpreter.setOut(out);
|
||||||
interpreter.setErr(out);
|
interpreter.setErr(out);
|
||||||
|
|
||||||
PyCode pyCode = BytecodeLoader.makeCode("test", code.getBytes(), getServletContext().getRealPath("/com/example/test.pyc")); // $ Alert[java/jython-injection]
|
PyCode pyCode = BytecodeLoader.makeCode("test", code.getBytes(), getServletContext().getRealPath("/com/example/test.pyc"));
|
||||||
interpreter.exec(pyCode);
|
interpreter.exec(pyCode);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ public class JythonInjection extends HttpServlet {
|
|||||||
interpreter.setOut(out);
|
interpreter.setOut(out);
|
||||||
interpreter.setErr(out);
|
interpreter.setErr(out);
|
||||||
|
|
||||||
PyCode pyCode = Py.compile(request.getInputStream(), "Test.py", org.python.core.CompileMode.eval); // $ Alert[java/jython-injection]
|
PyCode pyCode = Py.compile(request.getInputStream(), "Test.py", org.python.core.CompileMode.eval);
|
||||||
interpreter.exec(pyCode);
|
interpreter.exec(pyCode);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
query: experimental/Security/CWE/CWE-094/JythonInjection.ql
|
query: experimental/Security/CWE/CWE-094/JythonInjection.ql
|
||||||
postprocess:
|
postprocess: utils/test/PrettyPrintModels.ql
|
||||||
- utils/test/PrettyPrintModels.ql
|
|
||||||
- utils/test/InlineExpectationsTestQuery.ql
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user