Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Relocate Java CWE libraries to importable location #3923

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions java/ql/src/Security/CWE/CWE-022/PathsCommon.qll
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import java
import semmle.code.java.controlflow.Guards

abstract class PathCreation extends Expr {
abstract Expr getInput();
}
import semmle.code.java.security.PathCreation

class PathsGet extends PathCreation, MethodAccess {
PathsGet() {
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-089/SqlTainted.ql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java
import semmle.code.java.dataflow.FlowSources
import SqlInjectionLib
import semmle.code.java.security.SqlInjection
import DataFlow::PathGraph

from QueryInjectionSink query, DataFlow::PathNode source, DataFlow::PathNode sink
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-089/SqlTaintedLocal.ql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import semmle.code.java.Expr
import semmle.code.java.dataflow.FlowSources
import SqlInjectionLib
import semmle.code.java.security.SqlInjection
import DataFlow::PathGraph

class LocalUserInputToQueryInjectionFlowConfig extends TaintTracking::Configuration {
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-089/SqlUnescaped.ql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java
import semmle.code.java.security.SqlUnescapedLib
import SqlInjectionLib
import semmle.code.java.security.SqlInjection

class UncontrolledStringBuilderSource extends DataFlow::ExprNode {
UncontrolledStringBuilderSource() {
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-090/LdapInjection.ql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java
import semmle.code.java.dataflow.FlowSources
import LdapInjectionLib
import semmle.code.java.security.LdapInjection
import DataFlow::PathGraph

from DataFlow::PathNode source, DataFlow::PathNode sink, LdapInjectionFlowConfig conf
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-113/ResponseSplitting.ql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import java
import ResponseSplitting
import semmle.code.java.security.ResponseSplitting
import DataFlow::PathGraph

class ResponseSplittingConfig extends TaintTracking::Configuration {
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-113/ResponseSplittingLocal.ql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java
import semmle.code.java.dataflow.FlowSources
import ResponseSplitting
import semmle.code.java.security.ResponseSplitting
import DataFlow::PathGraph

class ResponseSplittingLocalConfig extends TaintTracking::Configuration {
Expand Down
67 changes: 0 additions & 67 deletions java/ql/src/Security/CWE/CWE-129/ArraySizing.qll
Original file line number Diff line number Diff line change
Expand Up @@ -102,70 +102,3 @@ class CheckableArrayAccess extends ArrayAccess {
not lowerBound(sizeExpr) > 0
}
}

/**
* A source of "flow" which has an upper or lower bound.
*/
abstract class BoundedFlowSource extends DataFlow::Node {
/**
* Return a lower bound for the input, if possible.
*/
abstract int lowerBound();

/**
* Return an upper bound for the input, if possible.
*/
abstract int upperBound();

/**
* Return a description for this flow source, suitable for putting in an alert message.
*/
abstract string getDescription();
}

/**
* Input that is constructed using a `Random` value.
*/
class RandomValueFlowSource extends BoundedFlowSource {
RandomValueFlowSource() {
exists(RefType random, MethodAccess nextAccess |
random.hasQualifiedName("java.util", "Random")
|
nextAccess.getCallee().getDeclaringType().getAnAncestor() = random and
nextAccess.getCallee().getName().matches("next%") and
nextAccess = this.asExpr()
)
}

override int lowerBound() {
// If this call is to `nextInt()`, the lower bound is zero.
this.asExpr().(MethodAccess).getCallee().hasName("nextInt") and
this.asExpr().(MethodAccess).getNumArgument() = 1 and
result = 0
}

override int upperBound() {
// If this call specified an argument to `nextInt()`, and that argument is a compile time constant,
// it forms the upper bound.
this.asExpr().(MethodAccess).getCallee().hasName("nextInt") and
this.asExpr().(MethodAccess).getNumArgument() = 1 and
result = this.asExpr().(MethodAccess).getArgument(0).(CompileTimeConstantExpr).getIntValue()
}

override string getDescription() { result = "Random value" }
}

/**
* A compile time constant expression that evaluates to a numeric type.
*/
class NumericLiteralFlowSource extends BoundedFlowSource {
NumericLiteralFlowSource() { exists(this.asExpr().(CompileTimeConstantExpr).getIntValue()) }

override int lowerBound() { result = this.asExpr().(CompileTimeConstantExpr).getIntValue() }

override int upperBound() { result = this.asExpr().(CompileTimeConstantExpr).getIntValue() }

override string getDescription() {
result = "Literal value " + this.asExpr().(CompileTimeConstantExpr).getIntValue()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java
import ArraySizing
import semmle.code.java.security.BoundedFlow
import DataFlow::PathGraph

class BoundedFlowSourceConf extends DataFlow::Configuration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java
import ArraySizing
import BoundingChecks
import semmle.code.java.security.BoundedFlow
import DataFlow::PathGraph

class BoundedFlowSourceConf extends DataFlow::Configuration {
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-312/CleartextStorageClass.ql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import java
import SensitiveStorage
import semmle.code.java.security.SensitiveStorage

from SensitiveSource data, ClassStore s, Expr input, Expr store
where
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-312/CleartextStorageCookie.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import java
import SensitiveStorage
import semmle.code.java.security.SensitiveStorage

from SensitiveSource data, Cookie s, Expr input, Expr store
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import java
import SensitiveStorage
import semmle.code.java.security.SensitiveStorage

from SensitiveSource data, Properties s, Expr input, Expr store
where
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-601/UrlRedirect.ql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java
import semmle.code.java.dataflow.FlowSources
import UrlRedirect
import semmle.code.java.security.UrlRedirect
import DataFlow::PathGraph

class UrlRedirectConfig extends TaintTracking::Configuration {
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-601/UrlRedirectLocal.ql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java
import semmle.code.java.dataflow.FlowSources
import UrlRedirect
import semmle.code.java.security.UrlRedirect
import DataFlow::PathGraph

class UrlRedirectLocalConfig extends TaintTracking::Configuration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import java
import semmle.code.java.dataflow.DataFlow
import HardcodedCredentials
import semmle.code.java.security.HardcodedCredentials
import DataFlow::PathGraph

class HardcodedCredentialApiCallConfiguration extends DataFlow::Configuration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import java
import HardcodedCredentials
import semmle.code.java.security.HardcodedCredentials

class EqualsAccess extends MethodAccess {
EqualsAccess() { getMethod() instanceof EqualsMethod }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java
import semmle.code.java.dataflow.DataFlow
import semmle.code.java.dataflow.DataFlow2
import HardcodedCredentials
import semmle.code.java.security.HardcodedCredentials
import DataFlow::PathGraph

class HardcodedCredentialSourceCallConfiguration extends DataFlow::Configuration {
Expand Down
2 changes: 1 addition & 1 deletion java/ql/src/Security/CWE/CWE-798/HardcodedPasswordField.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import java
import HardcodedCredentials
import semmle.code.java.security.HardcodedCredentials

from PasswordVariable f, CompileTimeConstantExpr e
where
Expand Down
69 changes: 69 additions & 0 deletions java/ql/src/semmle/code/java/security/BoundedFlow.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import java
import semmle.code.java.dataflow.DataFlow

/**
* A source of "flow" which has an upper or lower bound.
*/
abstract class BoundedFlowSource extends DataFlow::Node {
/**
* Return a lower bound for the input, if possible.
*/
abstract int lowerBound();

/**
* Return an upper bound for the input, if possible.
*/
abstract int upperBound();

/**
* Return a description for this flow source, suitable for putting in an alert message.
*/
abstract string getDescription();
}

/**
* Input that is constructed using a `Random` value.
*/
class RandomValueFlowSource extends BoundedFlowSource {
RandomValueFlowSource() {
exists(RefType random, MethodAccess nextAccess |
random.hasQualifiedName("java.util", "Random")
|
nextAccess.getCallee().getDeclaringType().getAnAncestor() = random and
nextAccess.getCallee().getName().matches("next%") and
nextAccess = this.asExpr()
)
}

override int lowerBound() {
// If this call is to `nextInt()`, the lower bound is zero.
this.asExpr().(MethodAccess).getCallee().hasName("nextInt") and
this.asExpr().(MethodAccess).getNumArgument() = 1 and
result = 0
}

override int upperBound() {
// If this call specified an argument to `nextInt()`, and that argument is a compile time constant,
// it forms the upper bound.
this.asExpr().(MethodAccess).getCallee().hasName("nextInt") and
this.asExpr().(MethodAccess).getNumArgument() = 1 and
result = this.asExpr().(MethodAccess).getArgument(0).(CompileTimeConstantExpr).getIntValue()
}

override string getDescription() { result = "Random value" }
}

/**
* A compile time constant expression that evaluates to a numeric type.
*/
class NumericLiteralFlowSource extends BoundedFlowSource {
NumericLiteralFlowSource() { exists(this.asExpr().(CompileTimeConstantExpr).getIntValue()) }

override int lowerBound() { result = this.asExpr().(CompileTimeConstantExpr).getIntValue() }

override int upperBound() { result = this.asExpr().(CompileTimeConstantExpr).getIntValue() }

override string getDescription() {
result = "Literal value " + this.asExpr().(CompileTimeConstantExpr).getIntValue()
}
}
5 changes: 5 additions & 0 deletions java/ql/src/semmle/code/java/security/PathCreation.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import java

abstract class PathCreation extends Expr {
abstract Expr getInput();
}