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.
unsecure
attribute specifies a list of attributes whose values can be set on the client.unsecure
attribute of these components can specify such a list.unsecure
attribute is disabled
, and it allows the client to define which components are enabled and which ones are not. It is never a good idea to let the client control the values of attributes that should only be settable on the server.inputText
component that collects password information from the user and uses the unsecure
attribute.
...
<af:inputText id="pwdBox"
label="#{resources.PWD}"
value=""#{userBean.password}
unsecure="disabled"
secret="true"
required="true"/>
...
file://
protocol which may have undesirable security implications.file://
. It is not clear what their behavior should be, and what rules of security compartmentalization should apply. For example, should HTML files downloaded to local disk from the Internet share the same cookies as any HTML code installed locally?UseCookiePolicy()
method adds the cookie policy middleware to the middleware pipeline, allowing for customized cookie policies. When specified in the wrong order as shown, any cookie policy stated by the programmer will be ignored.
...
var builder = WebApplication.CreateBuilder(...);
var app = builder.Build(...);
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
...
}
app.UseCookiePolicy();
...
UseHttpsRedirection()
method adds HTTPS redirection middleware to the middleware pipeline, which allows for redirection of insecure HTTP requests to a secure HTTPS request. When specified in the wrong order as shown, no meaningful HTTPS redirection will occur before processing the request through the middleware listed before the redirect. This will allow for HTTP requests to be processed by the application before being redirected to the secure HTTPS connection.
...
var builder = WebApplication.CreateBuilder(...);
var app = builder.Build(...);
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
...
}
app.UseHttpsRedirection();
...
UseHttpLogging()
method adds HTTP logging middleware to the middleware pipeline which allows middleware components to log. When specified in the wrong order as shown, no middleware added to the pipeline before the call to UseHttpLogging()
will log.Example 2: The
...
var builder = WebApplication.CreateBuilder(...);
var app = builder.Build(...);
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
...
}
app.UseHttpLogging();
...
UseWC3Logging()
method adds W3C logging middleware to the middleware pipeline which allows middleware components to log. When specified in the wrong order as shown, no middleware added to the pipeline before the call to UseWC3Logging()
will log.
...
var builder = WebApplication.CreateBuilder(...);
var app = builder.Build(...);
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
...
}
app.UseWC3Logging();
...
public ActionResult UpdateWidget(Model model)
{
// ... controller logic
}
[Required]
attribute) and properties that are optional (as not marked with the [Required]
attribute) can lead to problems if an attacker communicates a request that contains more data than is expected.[Required]
and properties that do not have [Required]
:
public class MyModel
{
[Required]
public String UserName { get; set; }
[Required]
public String Password { get; set; }
public Boolean IsAdmin { get; set; }
}
[Required]
attribute) can lead to problems if an attacker communicates a request that contains less data than is expected.[Required]
validation attribute. This may produce unexpected application behavior.
public enum ArgumentOptions
{
OptionA = 1,
OptionB = 2
}
public class Model
{
[Required]
public String Argument { get; set; }
[Required]
public ArgumentOptions Rounding { get; set; }
}
[Required]
attribute -- and if an attacker does not communicate that submodel, then the parent property will have a null
value and the required fields of the child model will not be asserted by model validation. This is one form of an under-posting attack.
public class ChildModel
{
public ChildModel()
{
}
[Required]
public String RequiredProperty { get; set; }
}
public class ParentModel
{
public ParentModel()
{
}
public ChildModel Child { get; set; }
}
ParentModel.Child
property, then the ChildModel.RequiredProperty
property will have a [Required]
which is not asserted. This may produce unexpected and undesirable results.
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:nil
reply:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"Auth was OK");
}
}];
context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "", reply: { (success, error) -> Void in
if (success) {
print("Auth was OK");
}
else {
print("Error received: %d", error!);
}
})
SHARED
which allows both read and write access.
results = query.execute(Database.SHARED);
results = query.execute(); //missing query mode
GC.Collect()
sometimes seems to make the problem go away.GC.Collect()
is the wrong thing to do. In fact, calling GC.Collect()
can cause performance problems if it is invoked too often.System.gc()
sometimes seems to make the problem go away.System.gc()
is the wrong thing to do. In fact, calling System.gc()
can cause performance problems if it is invoked too often.Equals()
is called on an object that does not implement Equals()
.Equals()
on a class (or any super class/interface) that does not explicitly implement Equals()
results in a call to the Equals()
method inherited from System.Object
. Instead of comparing object member fields or other properties, Object.Equals()
compares two object instances to see if they are the same. Although there are legitimate uses of Object.Equals()
, it is often an indication of buggy code.
public class AccountGroup
{
private int gid;
public int Gid
{
get { return gid; }
set { gid = value; }
}
}
...
public class CompareGroup
{
public bool compareGroups(AccountGroup group1, AccountGroup group2)
{
return group1.Equals(group2); //Equals() is not implemented in AccountGroup
}
}
equals()
method is called on an object that does not implement equals()
.equals()
on a class (or any super class/interface) that does not explicitly implement equals()
results in a call to the equals()
method inherited from java.lang.Object
. Instead of comparing object member fields or other properties, Object.equals()
compares two object instances to see if they are the same. Although there are legitimate uses of Object.equals()
, it is often an indication of buggy code.
public class AccountGroup
{
private int gid;
public int getGid()
{
return gid;
}
public void setGid(int newGid)
{
gid = newGid;
}
}
...
public class CompareGroup
{
public boolean compareGroups(AccountGroup group1, AccountGroup group2)
{
return group1.equals(group2); //equals() is not implemented in AccountGroup
}
}
finalize()
method should call super.finalize()
.finalize()
method to call super.finalize()
[1].super.finalize()
.
protected void finalize() {
discardNative();
}
private void writeObject(java.io.ObjectOutputStream out) throws IOException;
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException;
private void readObjectNoData() throws ObjectStreamException;
getWriter()
after calling getOutputStream
or vice versa.HttpServletRequest
, redirecting an HttpServletResponse
, or flushing the servlet's output stream buffer causes the associated stream to commit. Any subsequent buffer resets or stream commits, such as additional flushes or redirects, will result in IllegalStateException
s.ServletOutputStream
or PrintWriter
, but not both. Calling getWriter()
after having called getOutputStream()
, or vice versa, will also cause an IllegalStateException
.IllegalStateException
prevents the response handler from running to completion, effectively dropping the response. This can cause server instability, which is a sign of an improperly implemented servlet.Example 2: Conversely, the following code attempts to write to and flush the
public class RedirectServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
...
OutputStream out = res.getOutputStream();
...
// flushes, and thereby commits, the output stream
out.flush();
out.close(); // redirecting the response causes an IllegalStateException
res.sendRedirect("http://www.acme.com");
}
}
PrintWriter
's buffer after the request has been forwarded.
public class FlushServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
...
// forwards the request, implicitly committing the stream
getServletConfig().getServletContext().getRequestDispatcher("/jsp/boom.jsp").forward(req, res);
...
// IllegalStateException; cannot redirect after forwarding
res.sendRedirect("http://www.acme.com/jsp/boomboom.jsp");
PrintWriter out = res.getWriter();
// writing to an already-committed stream will not cause an exception,
// but will not apply these changes to the final output, either
out.print("Writing here does nothing");
// IllegalStateException; cannot flush a response's buffer after forwarding the request
out.flush();
out.close();
}
}
Content-Length
header is set as negative.Content-Length
header of a request indicates a developer is interested in0
or aContent-Length
.
URL url = new URL("http://www.example.com");
HttpURLConnection huc = (HttpURLConnection)url.openConnection();
huc.setRequestProperty("Content-Length", "-1000");
Content-Length
header is set as negative.Content-Length
header of a request indicates a developer is interested in0
or aContent-Length
header as negative:
xhr.setRequestHeader("Content-Length", "-1000");
ToString()
is called on an array.ToString()
on an array indicates a developer is interested in returning the contents of the array as a String. However, a direct call to ToString()
on an array will return a string value containing the array's type.System.String[]
.
String[] stringArray = { "element 1", "element 2", "element 3", "element 4" };
System.Diagnostics.Debug.WriteLine(stringArray.ToString());
toString()
is called on an array.toString()
on an array indicates a developer is interested in returning the contents of the array as a String. However, a direct call to toString()
on an array will return a string value containing the array's type and hashcode in memory.[Ljava.lang.String;@1232121
.
String[] strList = new String[5];
...
System.out.println(strList);