You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

 

The Java development guidelines in the chart below refer to guidelines in the book, "Java Coding Guidelines: 75 Recommendations for Reliable and Secure Programs".

 

Guideline
Applicable to Android Application Development?
Comments
1. Do not store unencrypted sensitive information on the client sideApplicable 
2. Limit the lifetime of sensitive dataApplicable in principleThe non-compliant code example is probably not problematic on Dalvik because each app has its own Dalvik VM and string objects would not be accessible from other apps (?)
3. Provide sensitive mutable classes with unmodifiable wrappersUnknown?
4. Ensure security-sensitive methods are called with validated argumentsApplicable in principleOn Android, accessControlContext is not available.
5. Prevent arbitrary file uploadNot applicable 
6. Properly encode or escape outputApplicable in principle 
7. Prevent code injectionApplicable in principleScriptEngineManager is not included in the Android SDK.
8. Prevent XPath InjectionApplicable 
9. Prevent LDAP injectionApplicable in principleApplicable in principle for android apps that tries to implement its own LDAP
10. Do not use the clone method to copy untrusted method parametersApplicable 
11. Do not use Object.equals() to compare cryptographic keysApplicable 
12. Do not use insecure or weak cryptographic algorithmsApplicable 
13. Store passwords using a hash functionApplicable 
14. Ensure SecureRandom is properly seededApplicable 
15. Do not rely on overridden methods provided by untrusted codeApplicable 
16. Avoid granting excess privilegesNot applicableAndroid does not use AccessController.
17. Minimize privileged codeNot applicableAndroid does not use AccessController.
18. Do not expose methods that use reduced-security checks to untrusted codeNot applicable 
19. Define custom security permissions for fine-grained securityNot applicable 
20. Create a secure sandbox using a security managerNot applicable 
21. Do not let untrusted code misuse privileges of callback methodsUnknown 
22. Minimize the scope of variablesApplicable 
23. Minimize the scope of the @SuppressWarnings annotationApplicable 
24. Minimize the accessibility of classes and their membersApplicable 
25. Document thread-safety and use annotations where applicableApplicable 
26. Always provide feedback about the resulting value of a methodApplicable 
27. Identify files using multiple file attributesApplicable in principleOn Android, better to use openFileOutput/openFileInput for file I/O.
28. Do not attach significance to the ordinal associated with an enumApplicable 
29. Be aware of numeric promotion behaviorApplicable 
30. Enable compile-time type checking of variable arity parameter typesApplicable 
31. Do not apply public final to constants whose value might change in later releasesApplicable 
32. Avoid cyclic dependencies between packagesApplicable 
33. Prefer user-defined exceptions over more general exception typesApplicable 
34. Try to gracefully recover from system errorsApplicable 
35. Carefully design interfaces before releasing themApplicable 
36. Write garbage-collection-friendly codeApplicable 
37. Do not shadow or obscure identifiers in subscopesApplicable 
38. Do not declare more than one variable per declarationApplicable 
39. Use meaningful symbolic constants to represent literal values in program logicApplicable 
40. Properly encode relationships in constant definitionsApplicable 
41. Return an empty array or collection instead of a null value for methods that return an array or collectionApplicable 
42. Use exceptions only for exceptional conditionsApplicable 
43. Use a try-with-resources statement to safely handle closeable resourcesNot applicableThe current Android SDK does not support Java7, thus try-with-resource is not available
44. Do not use assertions to verify the absence of runtime errorsApplicable in principleOn Android, assert() is ignored by default.
45. Use the same type for the second and third operands in conditional expressionsApplicable 
46. Do not serialize direct handles to system resourcesApplicable 
47. Prefer using iterators over enumerationsApplicable 
48. Do not use direct buffers for short-lived, infrequently used objectsApplicable 
49. Remove short-lived objects from long-lived container objectsApplicable 
50. Be careful using visually misleading identifiers and literalsApplicable 
51. Avoid ambiguous overloading of variable arity methodsApplicable 
52. Avoid in-band error indicatorsApplicable 
53. Do not perform assignments in conditional expressionsApplicable 
54. Use braces for the body of an if, for, or while statementApplicable 
55. Do not place a semicolon immediately following an if, for, or while conditionApplicable 
56. Finish every set of statements associated with a case label with a break statementApplicable 
57. Avoid inadvertent wrapping of loop countersApplicable 
58. Use parentheses for precedence of operationApplicable 
59. Do not make assumptions about file creationApplicable in principleOn Android, java.nio.file is not available.
60. Convert integers to floating-point for floating-point operationsApplicable 
61. Ensure that the clone() method calls super.clone()Applicable 
62. Use comments consistently and in a readable fashionApplicable 
63. Detect and remove superfluous code and valuesApplicable 
64. Strive for logical completenessApplicable 
65. Do not assume that declaring a reference volatile guarantees safe publication of the members of the referenced objectApplicable 
66. Do not assume that the sleep(), yield(), or getState() methods provide synchronization semanticsApplicable 
67. Do not assume that the remainder operator always returns a nonnegative result for integral operandsApplicable 
68. Do not confuse abstract object equality with reference equalityApplicable 
69. Understand the differences between bitwise and logical operatorsApplicable 
70. Understand how escape characters are interpreted when strings are loadedApplicable 
71. Avoid ambiguous or confusing uses of overloadingApplicable 
72. Do not use overloaded methods to differentiate between runtime typseApplicable 
73. Never confuse the immutability of a reference with that of the referenced objectApplicable 
74. Use the serialization methods writeUnshared() and readUnshared() with careApplicable 
75. Do not attempt to help the garbage collector by setting local reference variables to nullApplicable 

Bibliography

[Long 2013]Java Coding Guidelines: 75 Recommendations for Reliable and Secure Programs

ENV05-J. Do not deploy an application that can be remotely monitored The CERT Oracle Secure Coding Standard for Java MSC00-J. Use SSLSocket rather than Socket for secure data exchange

 

  • No labels