An API is a contract between a caller and a callee. The most common forms of API abuse are caused by the caller failing to honor its end of this contract. For example, if a program fails to call chdir() after calling chroot(), it violates the contract that specifies how to change the active root directory in a secure fashion. Another good example of library abuse is expecting the callee to return trustworthy DNS information to the caller. In this case, the caller abuses the callee API by making certain assumptions about its behavior (that the return value can be used for authentication purposes). One can also violate the caller-callee contract from the other side. For example, if a coder subclasses SecureRandom and returns a non-random value, the contract is violated.
[FromBody]
annotation is used.[FromBody]
annotation is applied to a complex parameter of an action, then any other binding attributes such as [Bind]
or [BindNever]
applied to the type of the parameter or any of its fields are effectively ignored, which means that mitigation using binding annotations is impossible.[FromBody]
annotation is applied to a parameter of an action, the model binder automatically tries to bind all parameters specified in the body of the request using an Input Formatter. By default, the binder uses the JSON Input Formatter to try and bind all possible parameters that come from the body of the request:
[HttpPost]
public ActionResult Create([FromBody] Product p)
{
return View(p.Name);
}
[Bind]
or [BindNever]
applied to the Product
type that follows are ignored due to Input Formatters being used when the [FromBody]
annotation is present.
public class Product
{
...
public string Name { get; set; }
public bool IsAdmin { get; set; }
...
}
null
.Item
property is null
before calling the member function Equals()
, potentially causing a null
dereference.
string itemName = request.Item(ITEM_NAME);
if (itemName.Equals(IMPORTANT_ITEM)) {
...
}
...
null
value."null
.malloc()
.
buf = (char*) malloc(req_size);
strncpy(buf, xfer, req_size);
malloc()
fail because req_size
was too large or because there were too many requests being handled at the same time? Or was it caused by a memory leak that has built up over time? Without handling the error, there is no way to know.null
.getParameter()
is null
before calling the member function compareTo()
, potentially causing a null
dereference.Example 2:. The following code shows a system property that is set to
String itemName = request.getParameter(ITEM_NAME);
if (itemName.compareTo(IMPORTANT_ITEM)) {
...
}
...
null
and later dereferenced by a programmer who mistakenly assumes it will always be defined.
System.clearProperty("os.name");
...
String os = System.getProperty("os.name");
if (os.equalsIgnoreCase("Windows 95") )
System.out.println("Not supported");
null
value."null
.Object.equals()
, Comparable.compareTo()
, and Comparator.compare()
must return a specified value if their parameters are null
. Failing to follow this contract may result in unexpected behavior.equals()
method does not compare its parameter with null
.
public boolean equals(Object object)
{
return (toString().equals(object.toString()));
}
clone()
method should call super.clone()
to obtain the new object.clone()
should obtain the new object by calling super.clone()
. If a class fails to follow this convention, a subclass's clone()
method will return an object of the wrong type.super.clone()
. Because of the way Kibitzer
implements clone()
, FancyKibitzer
's clone method will return an object of type Kibitzer
instead of FancyKibitzer
.
public class Kibitzer implements Cloneable {
public Object clone() throws CloneNotSupportedException {
Object returnMe = new Kibitzer();
...
}
}
public class FancyKibitzer extends Kibitzer
implements Cloneable {
public Object clone() throws CloneNotSupportedException {
Object returnMe = super.clone();
...
}
}
Equals()
and GetHashCode()
.a.Equals(b) == true
then a.GetHashCode() == b.GetHashCode()
.Equals()
but not GetHashCode()
.
public class Halfway() {
public override boolean Equals(object obj) {
...
}
}
equals()
and hashCode()
.a.equals(b) == true
then a.hashCode() == b.hashCode()
.equals()
but not hashCode()
.
public class halfway() {
public boolean equals(Object obj) {
...
}
}
saveState()
and restoreState()
.saveState(javax.faces.context.FacesContext)
and restoreState(javax.faces.context.FacesContext, java.lang.Object)
or implement neither of them. Because these two methods have a tightly coupled relationship, it is not permissible to have the saveState(javax.faces.context.FacesContext)
and restoreState(javax.faces.context.FacesContext, java.lang.Object)
methods reside at different levels of the inheritance hierarchy.saveState()
and not restoreState()
, so it is always in error no matter what any class that extends
public class KibitzState implements StateHolder {
public Object saveState(FacesContext fc) {
...
}
}