Index

Symbols

& (AND)

bitwise vs. logical operators, 225228

precedence of operation, 186187

&& (AND)

assignments in conditional expressions, 176177

bitwise vs. logical operators, 225228

| (OR)

bitwise vs. logical operators, 225228

numeric promotion behavior, 110

precedence of operation, 186

|| (OR)

assignments in conditional expressions, 176

bitwise vs. logical operators, 225228

% (remainder operator), 220222

() (parentheses), 186188

*/ (asterisk backslash), 196197

' (single quote), 27

" (double quotes)

output sanitization, 19

preventing XPath injection, 27

/ (backslash), 27

/* (backslash asterisk), 196197

// (double backslash), 196

; (semicolon), 180181

?: (conditional operator), 153, 176

!= (equality operator), 222

^ (caret), 186

{} (braces), 178180

Image (PI), 139140

<> (angle braces)

output sanitization, 19

preventing XPath injection, 27

<< (comparison operators), 186

= (assignment operator), 176178

== (equality operator), 70, 222225

>> (comparison operators), 186

A

abstract classes, 126127

Abstract object equality, 222225

Abstract Window Toolkit (AWT), 95

Access control

avoid granting excess privileges, 5053

calling security-sensitive methods with validated arguments, 1113

java.util.Date, 33

minimize accessibility of classes and their members, 8489

AccessControlContext

avoid granting excess privileges, 5253

preventing code injection, 22

AccessController

doPrivileged(), 51

SecurityManager, 68

Advanced Encryption Standard (AES), 3637

allowedType, 14

Always provide feedback about resulting value of method, 9699

AND (&)

bitwise vs. logical operators, 225228

precedence of operation, 186187

AND (&&)

assignments in conditional expressions, 176177

bitwise vs. logical operators, 225228

Android guidelines applicability, 245246

Angle braces (<>)

output sanitization, 19

preventing XPath injection, 27

Annotations

document thread-safety, 8996

scope of @SuppressWarnings, 8284

Apache Geronimo and Tomcat vulnerability, 130

API

careful interface design, 125128

minimize accessibility of classes and their members, 85, 89

prefer using iterators over enumerations, 159161

providing feedback about resulting method values, 9699

scope of guidelines, xv

SecurityManager, 7071

writeUnshared(), 239

Applet security managers, 68

appletviewer, 70

Arbitrary code

output sanitization, 1619

preventing upload, 1316

Arguments, validated, 1113

Arithmetic operations

floating-point operations, 191194

precedence of operation, 186188

ArrayIndexOutOfBoundsException, 147

ArrayList

minimize scope of @SuppressWarnings, 8384

remove short-lived objects from long-lived container objects, 163164

Arrays

return empty instead of null, 143146

safe publication guarantee and volatile, 210211

ASCII character set, 168

assert, 151153

Assignment operators (=), 176178

Assignments, 175178

Assumptions. See Programmer misconceptions

Asterisk backslash (*/), 196197

AtomicIntegerArray, 211

Atomicity

defined, 249

preserving compound operation, 213

AtomicReferenceArray, 3334

Attributes, 99106

Audience, xvii

Authentication

preventing LDAP injection, 2931

preventing XPath injection, 24

AutoDetectParser, 1516

Avoid ambiguous or confusing uses of overloading, 205208

Avoid ambiguous overloading of variable arity methods, 171173

Avoid cyclic dependencies between packages, 118121

Avoid granting excess privileges, 5053

Avoid in-band error indicators, 173175

Avoid inadvertent wrapping of loop counters, 183186

AWT (Abstract Window Toolkit), 95

B

Backslash (/), 27

Backslash asterisk (/*), 196197

Backward compatibility of SecurityManager, 68

BasicPermission, 6567

Be aware of numeric promotion behavior, 108112

Be careful using visually misleading identifiers and literals, 167171

Bitwise vs. logical operators, 225228

Bloch, Joshua

overloading methods, 207

on thread-safety annotations, 92

Block comments, 196198

Booleans

feedback about resulting method values, 97

meaningful symbolic constants to represent, 138

type use for second and third operands in conditional expressions, 153154

Braces ({}), 178180

break statement, 181183

BufferedReader

file identification, 100

limiting lifetime of sensitive data, 24

Buffers

helping garbage collector, 243244

limiting lifetime of sensitive data, 25

short-lived infrequently used objects and, 162163

Bugs, xvxvi

byte array, 4041

Bytecode verifier, 1

C

Callback methods, 7277

CallBackAction, 7277

Canonicalization

custom, 225

defined, 213

Carefully design interfaces before releasing them, 125128

Caret (^), 186

case, 181183

catch, 146147

The CERT® Oracle® Secure Coding Standard for Java™ (Long)

CERT Vulnerability Note VU#636312, 6062

defined, xiv

exception NUM12-EX0 of NUM12-J, 155

feedback about resulting method values, 96

graceful recovery from system errors, 124

in-band error indicators, 173

premature optimization, 140141

preventing code injection, 20

random number generation, 42

reduced security checks, 58

safe publication, 94

try-with-resources statement, 148

unchecked warnings, 82

wrapping sensitive mutable classes, 10

changePassword(), 5455

Characters

to exclude from whitelists, 28

how escape characters are interpreted when strings are loaded, 228231

meaningful symbolic constants to represent, 138

preventing XPath injection, 27

type use for second and third operands in conditional expressions, 153154

visually misleading identifiers and literals, 167168

checkMetaData(), 15

checkPackageAccess(), 62

checkPassword(), 41

Class loaders, 5658, 6062

Class variables, 249

Classes

minimizing accessibility of, 8489

minimizing scope of @SuppressWarnings, 8283

security, 1

SecurityManager, 6772

unmodifiable wrappers for sensitive mutable, 911

Class.forName(), 6164

Client-side storage of sensitive information, 59

clone()

ensuring it calls super.clone(), 194196

final variable and, 236237

untrusted method parameters, 3134

Closeable resources, 148151

Code

detect and remove superfluous, 198202

garbage-collection-friendly, 128130

injection, 2023

Java guidelines and standards, xivxv

source, 5051

style, xvii

understandability. See Program understandability

CodeSource, 5051

Collections

iterators vs. enumerations, 159161

returning empty instead of null, 143146

unmodifiable wrappers for sensitive mutable classes, 9

Command-line security manager installation, 6970

Comment consistency and readability, 196198

Comparison operations

abstract object equality vs. reference equality, 222225

cryptographic keys, 3435

terminating loops, 185

Comparison operators (>>), 186

Comparison operators (<<), 186

Compile-time checking of variable arity parameter types, 112115

Compound operators, 109, 111112

Concurrency annotations, 90

Condition predicate

defined, 249

wait-notify protocols, 95

Conditional expressions

assignments in, 175178

bitwise vs. logical operators, 225228

same type for second and third operands in, 153157

Conditional operator (?:), 153, 176

Constants

application of public final, 115118

encoding relationships in definitions, 142143

representing literal values in program logic, 138142

Constructor overloading, 205206

Controlling expression, 95, 175178, 249

Controversial guidelines, xvii

Convert integers to floating point for floating-point operations, 191194

Cookies, 59

Copying

providing functionality with clone(), 236238

untrusted method parameter, 3134

counter(), 8182

Create secure sandbox using security manager, 6772

createNewFile(), 189190

createSecurityManager, 68

Creative Commons Attribution License, 90

Cross-Site Scripting (XSS) attacks

output sanitization, 1619

storing unencrypted sensitive information, 56

Cryptographic algorithms, 3637

Cryptographic hash functions, 3738

Cryptographic key comparison, 3435

Custom security manager, 71

Custom security permissions, 6467

Custom security policies, 68

Cyclic dependencies, 118121

D

DAG (directed acyclic graph), 118

Data Encryption Standard (DES), 36

Data races. See also Race conditions

defined, 249

preventing, 96

Data, sensitive. See Sensitive data

DataElement, 164165

DateFormat, 214215

Dead code, 198202

Deadlock, 249

Decimal values, 170

Declarations, 134137

Default exception handler, 6567

default label

defined, 181183

logical completeness, 203

Default security manager, 6971

Defensive programming

always provide feedback about resulting value of method, 9699

application of public final to constants whose value might change, 115118

avoid cyclic dependencies between packages, 118121

be aware of numeric promotion behavior, 108112

carefully design interfaces before releasing them, 125128

do not attach significance to ordinal associated with enum, 106108

document thread-safety and use annotations where applicable, 8996

enable compile-time type checking of variable arity parameter types, 112115

identify files using multiple file attributes, 99106

minimize accessibility of classes and their members, 8489

minimize scope of @SuppressWarnings annotation, 8284

minimize scope of variables, 8082

overview, 79

prefer user-defined exceptions over more general exception types, 121123

try to gracefully recover from system errors, 123125

write garbage-collection-friendly code, 128130

Define custom security permissions for fine-grained security, 6467

Delegating method implementation, 126

delete(), 99

Delimiters, 196197

Denial-of-service (DoS)

garbage-collection-friendly code, 128129

graceful recovery from system errors, 124125

inadvertent wrapping of loop counters, 186

returning empty array or collection instead of null value, 143, 146

verifying absence of runtime errors, 152

Dependencies, cyclic, 118121

DES (Data Encryption Standard), 36

Design

intent, 89

interface, 125128

Detect and remove superfluous code and values, 198202

Direct buffers, 162163

Directed acyclic graph (DAG), 118

Directories, 99

-disableassertions (-da), 151

display(), 232233

displayBooleans(), 171172

Division, 191193

do ... while, 175

Document thread-safety and use annotations where applicable, 8996

Documentation

consistency and readability, 196198

thread-safety and use annotations where applicable, 8996

doPrivileged()

avoid granting excess privileges, 52

calling security-sensitive methods with validated arguments, 12

do not expose methods that use reduced-security checks to untrusted code, 5859

do not let untrusted code misuse privileges of callback methods, 7577

minimize privileged code, 5455

preventing code injection, 22

DoS (denial-of-service). See Denial-of-service (DoS)

doSomething()

synchronization semantics, 218219

user-defined exceptions, 122

double

floating-point operations, 192193

numeric promotion behavior, 108111

Double backslash (//), 196

Double quotes (")

output sanitization, 19

preventing XPath injection, 27

E

E, 140

Electronic Frontier Foundation’s (EFF) Deep Crack, 36

Empty arrays and collections, 143144

Enable compile-time type checking of variable arity parameter types, 112115

Encoding

proper output, 1620

relationships in constant definitions, 142143

Encryption

storing passwords using hash functions, 3742

using secure algorithms, 3637

End-of-line comments, 196198

Ensure security-sensitive methods are called with validated arguments, 1113

Ensure that clone() method calls super.clone(), 194196

Ensure that SecureRandom is properly seeded, 4243

enum

do not attach significance to ordinal associated with an, 106108

prefer using iterators over, 159161

thread-safety annotations, 92

Equality operator (==), 70, 222225

Equality operator (!=), 222

equals()

abstract object equality vs. reference equality, 222225

comparing cryptographic keys, 3435

do not rely on methods that can be overridden by untrusted code, 4445

Errors

avoid in-band indicators, 173175

graceful recovery from system, 123125

providing feedback about resulting method values, 9699

reliability, xiii

verifying absence of runtime, 151153

Escape characters, 228231

Escaping output, 1620

evaluate(), 24

ExceptionReporterPermission, 6567

Exceptions

assumptions about file creation, 189190

avoid in-band error indicators, 173

graceful recovery from system errors, 123125

providing feedback about resulting method values, 9699

try-with-resources statement, 148151

use for exceptional conditions, 146148

user-defined vs. general types, 121123

F

false, 97

Federally funded research and development center (FFRDC), xvii

Feedback, 9699

Field shadowing, 132133

“File not found”, 122

FileChannel.size(), 105

fileKey, 103104

filename, 100

Files

assumptions about creation, 189190

do not serialize direct handles to system resources, 157158

identifying using multiple file attributes, 99106

preventing arbitrary upload, 1316

Files.isSameFile(), 101102

filter, 3031

final

application of public final to constants, 115118

immutability of reference vs. referenced object, 234238

final class

do not rely on methods that can be overridden by untrusted code, 47, 49

minimize accessibility of classes and their members, 8687

Finalizers, 243

finally block

graceful recovery from system errors, 123124

try-with-resources statement and, 149

findClass(), 6162

Finish every set of statements associated with case label with break statement, 181183

Fixes, 125

Flashback, 33

float, 108111

Floating-point numbers

convert integers to, 191194

meaningful symbolic constants to represent, 138

for

assignments in conditional expressions, 175

declaring variables separately, 136137

do not place semicolon immediately following, 180181

inadvertent wrapping of loop counters, 183186

minimizing scope of variables, 8082

use braces for, 178180

use exceptions only for exceptional conditions, 147

format, 214

G

Garbage collector (GC)

garbage collection–friendly code, 128130

remove short-lived objects from long-lived container objects, 163164

setting local reference variables to null, 243244

short-lived, infrequently used objects, 162

Generational garbage collection, 129

Generic type parameters, 112115

getArray(), 911

getConnection(), 5960

getData(), 206208

getFirst(), 210211

getState(), 218220

getTime(), 33

getVersion(), 116117

Goetz, Brian

documenting locking policies, 92

documenting wait-notify protocols, 95

Granting privileges, 5053

@GuardedBy, 91, 9293

H

Happens-before relationship, 211212, 252

Hash functions, 3742

hashCode()

abstract object equality vs. reference equality, 222

methods that can be overridden by untrusted code, 4446, 4849

hashKey, 221222

Heap memory, 250

heavilyUsedBuffer, 162

Hide, 132, 250

HTML files, 1316

HTML renderers, 16

HttpSession, 78

I

Identifiers

be careful using visually misleading, 167171

do not shadow or obscure in subscopes, 132134

using multiple file attributes, 99106

IdentityHashMap, 4647

if

assignments in conditional expressions, 175177

bitwise vs. logical operators, 227

do not place semicolon immediately following, 180181

logical completeness, 202

use braces for, 178180

Immutability

confusing reference with referenced object, 234239

defined, 252

short-lived objects, 129

thread-safety annotations, 9192

unmodifiable wrappers for sensitive mutable classes, 910

@Immutable, 91

imod(), 221222

In-band error indicators, 173175

Index variable, 8082

Indirect buffers, 162163

Initialization, 135

Injection attacks

Java security, 12

prevent code, 2023

prevent LDAP, 2731

prevent XPath, 2327

Input

normalization, 3031

verification, 152

Insecure cryptographic algorithms, 3637

Installing security manager, 6972

Integers

convert for floating-point operations, 191194

inadvertent wrapping of loop counters, 184186

meaningful symbolic constants to represent, 138

numeric promotion behavior, 108112

Integral operands, 220222

Intent of programmer

Java guidelines and, xiv

visually misleading identifiers and literals, 168

Interfaces

careful design, 125128

cyclic dependencies between packages, 119121

Interned strings, 223225

IsSameFile(), 101102

Iterators, 159161

-J Flag, 70

J

Java Concurrency in Practice (Goetz), 90

Java Language Specification (JLS)

be careful using visually misleading identifiers and literals, 167168

escape characters, 229

final fields and constants, 116

final variables, 234

numeric promotion behavior, 108

on obscuring, 132

ordinal associated with enum, 106

remainder operators, 220221

rules for determining result type of conditional expression, 153154

scope of guidelines, xv

security, 1

sleep() and yield(), 215

String.intern(), 224

types of exceptions, 123

volatile fields, 209

Java Naming and Directory Interface (JNDI) metacharacters, 2728

Java SE 7 Platform, xv, xvi

Java Virtual Machine (JVM)

graceful recovery from system errors, 123

password storage, 40

reduced security checks, 56

scope of guidelines, xv

security, 1

String.intern(), 224

synchronization semantics, 219

java.io, 189

java.io.File, 99

java.nio, 162

java.nio.file.Path, 99

java.policy, 6970

JavaScript code injection, 2023

java.util.Date, 33

java.util.regex.Pattern, 228

javax, xvi, 20

JCIP (Java Concurrency in Practice) annotations, 90

JITs (just-in-time compilers), 243

JLS (Java Language Specification), see Java Language Specification (JLS)

JNDI (Java Naming and Directory Interface) metacharacters, 2728

JSure tool, 90

Just-in-time compilers (JITs), 243

JVM (Java Virtual Machine). See Java Virtual Machine (JVM)

K

Key classes, 3435

L

Large objects, 129

Latin-1 characters, 168

LayoutManager, 4749

LDAP (Lightweight Directory Access Protocol) injection, 2731

Libraries, xvxvi

LicenseManager, 4447

Lifetime of sensitive data, 25

Lightweight Directory Access Protocol (LDAP) injection, 2731

Limit lifetime of sensitive data, 25

List, 207, 232233

Literal values

be careful using visually misleading, 167171

use meaningful symbolic constants to represent, 138142

Liveness, 243, 250

Loading libraries, 6567

Locking policies, 9294

Logical completeness, 202204

Logical operators, 225228

Logs, 123124

long, 108109

Long-lived container objects, 163165

Loops

declaring variables separately, 136137

inadvertent wrapping of loop counters, 183186

logical completeness, 203204

M

Maintenance, 118

MaliciousCallBack, 75

Map, 212

Mathematical expressions

floating-point operations, 191194

precedence of operation, 186188

MD5 (Message-Digest Algorithm), 38

Memory

garbage-collection-friendly code, 128130

limiting lifetime of sensitive data, 24

OutOfMemoryError, 125

remove short-lived objects from long-lived container objects, 163165

Memory model

defined, 250251

volatile fields, 209

Message-Digest Algorithm (MD5), 38

MessageDigest, 3841

Messages, 121122

Metacharacters

preventing LDAP injection, 2728

preventing XPath injection, 27

Methods

accessibility of classes and their members, 8489

ambiguous overloading of variable arity, 171173

calling security-sensitive with validated arguments, 1113

copying untrusted parameters, 3134

ensuring that clone() calls super.clone(), 194196

exposure to untrusted code, 5664

feedback about resulting value of, 9699

file identification and, 99

in-band error indicators, 173

misuse of overloaded to differentiate between, 231233

overloading, 206208

overridden by untrusted code, 4450

privileges of callback, 7277

returning empty array or collection instead of null, 143146

scope of @SuppressWarnings, 82

synchronization, 213214

varargs, 112

writeUnshared() and readUnshared(), 239243

Minimize accessibility of classes and their members, 8489

Minimize privileged code, 5455

Minimize scope of @SuppressWarnings annotation, 8284

Minimize scope of variables, 8082

Misconceptions. See Programmer misconceptions

Misleading characters, 168

Model-view-controller (MVC), 17

Modularize interfaces, 127

move(), 99

Multiplication

converting integers for floating-point operations, 191192

numeric promotion behavior, 109110

Mutable classes

final variable and, 234235

provide sensitive with unmodifiable wrappers, 911

Mutable objects

applying static final, 115

construction annotations, 9495

safe publication guarantee and volatile, 210, 212215

N

Never confuse immutability of reference with that of referenced object, 234239

NIO (new I/O) buffer, 45

NodeNotFoundException, 98

Nonnative libraries, 59

Normalization, 3031, 251

Notation, 136137

Notify protocols, 9596

NOTREACHED, 196197

@NotThreadSafe, 92

Null Object pattern, 164165

null values

avoid in-band error indicators, 173

calling security-sensitive methods with validated arguments, 1113

do not attempt to help garbage collector, 243244

providing feedback about resulting method values, 9899

return empty array or collection instead of, 143146

Number, 113114

Numeric promotion behavior, 108112

O

Object

compile-time type checking of variable arity parameter types, 112113

declaring variables separately, 135136

immutability, 252

Object.equals()

abstract object equality vs. reference equality, 222225

comparing cryptographic keys, 3435

methods that can be overridden by untrusted code, 44

Object.hashCode(), 44

Obscure, 132, 251

Octal values, 170

Operands

floating-point, 191194

numeric promotion behavior, 108112

parentheses for precedence of operation, 186188

remainder operator results for integral, 220222

type use for second and third in conditional expressions, 153157

OR (|)

bitwise vs. logical operators, 225228

numeric promotion behavior, 110

precedence of operation, 186

OR (||)

assignments in conditional expressions, 176

bitwise vs. logical operators, 225228

ordinal(), 106108

OutOfMemoryError, 125, 162

Output sanitization, 1620

Overloading

avoid ambiguous or confusing uses of, 205208

misuse of methods to differentiate between, 231233

variable arity methods, 171173

Override, 251

P

Package dependencies, 118121

Package-private access, 8489

Parameters

avoid ambiguous or confusing uses of overloading, 205208

compile-time type checking of variable arity types, 112115

do not use clone() to copy untrusted method, 3134

preventing XPath injection, 2627

Parentheses (()), 186188

parse(), 214215

Passwords

limiting lifetime of sensitive data, 34

minimize privileged code, 5455

preventing XPath injection, 2427

store using hash function, 3742

Path, 99, 101

Pattern, 228231

performActionOnFile(), 5152

Performance

calling System.gc(), 130

reliability, 131

permgen, 224

Permissions. See also Privileges

assumptions about file creation, 189

avoid granting excess privileges, 5053

define custom security for fine-grained security, 6467

SecurityManager, 68

PI (Image), 139140

Platforms

Android guidelines applicability, 245246

scope of guidelines, xv

Point, 236237

Policy files, 6970

Precedence of operation, 186188

Predefined constants, 140

Prefer user-defined exceptions over more general exception types, 121123

Prefer using iterators over enumerations, 159161

Premature optimization, 140141

Prevent arbitrary file upload, 1316

Prevent code injection, 2023

Prevent LDAP injection, 2731

Prevent XPath injection, 2327

private classes

accessibility of classes and members, 8489

final variable and, 237238

private static, 116117

Privileges

avoiding excess, 5053

callback method, 7277

calling security-sensitive methods, 1113

minimizing privileged code, 5455

preventing code injection, 2223

processSingleString(), 146147

Program understandability

assignments in conditional expressions, 175178

avoid ambiguous or confusing uses of overloading, 205208

avoid ambiguous overloading of variable arity methods, 171173

avoid in-band error indicators, 173175

avoid inadvertent wrapping of loop counters, 183186

be careful using visually misleading identifiers and literals, 167171

convert integers to floating point for floating-point operations, 191194

detect and remove superfluous code and values, 198202

do not make assumptions about file creation, 189190

do not place semicolon immediately following if, for, or while condition, 180181

ensure that clone() method calls super.clone(), 194196

finish every set of statements associated with case label with break statement, 181183

overview, 167

parentheses for precedence of operation, 186188

strive for logical completeness, 202204

use braces for body of if, for, or while statement, 178180

use comments consistently and in readable fashion, 196198

Programmatic SecurityManager installation, 7071

Programmer intent, xiv

Programmer misconceptions

do not assume that declaring reference volatile guarantees safe publication of members of referenced object, 209216

do not assume that remainder operator always returns nonnegative result for integral operands, 220222

do not assume that sleep(), yield(), or getState() provide synchronization semantics, 216220

do not attempt to help the garbage collector by setting local reference variables to null, 243244

do not confuse abstract object equality with reference equality, 222225

do not use overloaded methods to differentiate between runtime types, 231233

never confuse immutability of reference with that of referenced object, 234239

overview, 209

understand differences between bitwise and logical operators, 225228

understand how escape characters are interpreted when strings are loaded, 228231

use serialization methods writeUnshared() and readUnshared() with care, 239243

Programming, defensive. See Defensive programming

Properly encode or escape output, 1620

Properly encode relationships in constant definitions, 142143

protected classes, 8489

Protection domain, 51

Provide sensitive mutable classes with unmodifiable wrappers, 911

public classes, 86

public final, 115118, 237238

Publishing objects

defined, 251

safe publication guarantee, 209216

R

Race conditions

assumptions about file creation, 189190

defined, 251

preventing with annotation, 96

preventing with state testing, 97

Random number generation, 4243

RandomAccessFile, 104

rarelyUsedBuffer, 162

Readability. See also Program understandability

comment consistency and readability, 196198

defined, 167

meaningful symbolic constants, 141

readObject(), 239

readUnshared(), 239243

Recovery, 123125

References

abstract object equality vs. reference equality, 222225

immutability vs. immutability of referenced object, 234239

safe publication guarantee and volatile, 209216

setting local variables to null, 243244

Referents, 210

@Region, 91

@RegionLock, 91, 9294

Registries, 4243

Relationship encoding, 142143

Releases

application of public final to constants whose value might change, 115118

avoid cyclic dependencies between packages, 118

careful interface design, 125128

Reliability

defined, xiii

do not declare more than one variable per declaration, 134137

do not serialize direct handles to system resources, 157158

do not shadow or obscure identifiers in subscopes, 132134

do not use assertions to verify absence of runtime errors, 151153

do not use direct buffers for short-lived, infrequently used objects, 162163

overview, 131132

prefer using iterators over enumerations, 159161

properly encode relationships in constant definitions, 142143

remove short-lived objects from long-lived container objects, 163165

return empty array or collection instead of null value for methods that return array or collection, 143146

use exceptions only for exceptional conditions, 146148

use meaningful symbolic constants to represent literal values in program logic, 138142

use same type for second and third operands in conditional expressions, 153157

use try-with-resources statement to safely handle closeable resources, 148151

Remainder operator (%), 220222

Remember-me functionality, 59

Remove short-lived objects from long-lived container objects, 163165

renameTo(), 99

Resources, 148151

RestrictedAccessControlContext, 22

Return empty array or collection instead of null value for methods that return array or collection, 143146

Reusability, 118

Robustness, 79

ROT13 cipher, 37

RSAPrivateCrtKey, 35

RSAPrivateKey, 35

run(), 4950

Runtime errors, 151153

Runtime types, 231233

RuntimeException, 147

S

Safe publication guarantee, 209216, 251

Safety, 251

Salt, 38

Sandbox, secure

create using security manager, 6772

preventing code injection, 2223

Sanitization

defined, 251

input, 3031

output, 1620

SCALe (Source Code Analysis Laboratory), xiv

Scherlis, William, 95

Scope

@SuppressWarnings annotation, 8284

variable, 8082

searchRecord(), 29

Secure Hash Algorithm (SHA), 38, 3940

Secure sandbox

create using security manager, 6772

preventing code injection, 2223

SecureRandom, 4243

Security

avoid granting excess privileges, 5053

carefully design interfaces before releasing them, 125126

create secure sandbox using security manager, 6772

define custom security permissions for fine-grained security, 6467

do not expose methods that use reduced-security checks to untrusted code, 5664

do not let untrusted code misuse privileges of callback methods, 7277

do not rely on methods that can be overridden by untrusted code, 4450

do not store unencrypted sensitive information on client side, 59

do not use clone() to copy untrusted method parameters, 3134

do not use insecure or weak cryptographic algorithms, 3637

do not use Object.equals() to compare cryptographic keys, 3435

ensure security-sensitive methods are called with validated arguments, 1113

ensure that SecureRandom is properly seeded, 4243

limit lifetime of sensitive data, 25

minimize privileged code, 5455

overview, 12

prevent arbitrary file upload, 1316

prevent code injection, 2023

prevent LDAP injection, 2731

prevent XPath injection, 2327

properly encode or escape output, 1620

provide sensitive mutable classes with unmodifiable wrappers, 911

store passwords using hash function, 3742

Security flaws

careful interface design, 126

defined, 252

nonnative libraries and, 59

Security manager

create secure sandbox using, 6772

defining permissions, 6465

preventing code injection, 2223

Security-sensitive methods, 1113

SecurityException, 65, 69

Semicolon (;), 180181

Sensitive code, 252

Sensitive data

defined, 252

limit lifetime of, 25

storing unencrypted sensitive information on, 59

Sensitive mutable classes, 911

Sentinel pattern, 164165

Serialization

do not serialize direct handles to system resources, 157158

writeUnshared() and readUnshared(), 239243

Server-side storage, 59

Servlet security managers, 68

Session-fixation attacks, 9

setArray(), 1011

setFirst(), 210211

setPassword(), 41

setSecurityManager, 68, 72

SHA (Secure Hash Algorithm), 38, 3940

Shadow, 132134, 252

Short-lived objects

do not use direct buffers for, 162163

garbage-collection-friendly code, 129

remove from long-lived container objects, 163165

shutdown(), 217

SimpleLock, 93

Simplicity, 79

Single quote ('), 27

sleep(), 216220

Software reliability. See Reliability

Source Code Analysis Laboratory (SCALe), xiv

Special characters, 2728

StackOverflowError, 124

startThread(), 4950

State

logical completeness, 202204

providing feedback about resulting method value, 9699

StateLock, 94

static, 225

static final, 138

stop(), 218219

Storage

password, 3742

unencrypted sensitive information, 59

storeDateInDB(), 3233

String

abstract object equality vs. reference equality, 222225

storing passwords using hash functions, 3940

String.intern(), 223225

Strings

how escape characters are interpreted when loaded, 228231

meaningful symbolic constants to represent, 138

Strive for logical completeness, 202204

Subclasses

ensuring that clone() calls super.clone(), 194196

interface design, 125, 128

Subobjects, 213

Subscopes, 132134

SubWorker, 4950

super.clone(), 194196

super.startThread(), 50

@SuppressWarnings, 8284

SureLogic, 90

Sutherland, Dean, 95

switch

assignments in conditional expressions, 176

dead code, 201

finishing case label statements with break, 181183

logical completeness, 202203

Symbolic constants, 138142

Symmetric key algorithm, 3839

Synchronization

defined, 252

safe publication guarantee and volatile, 211214

sleep(), yield(), and getState(), 216220

System errors, 123125

System resources, 157158

System.gc(), 130

System.loadLibrary(), 5455, 58

T

Tenured generation, 129

Terminating loops, 183186

Testing, 118

Thread-safety

defined, 252

documenting, 8996

volatile references and, 210, 214216

Thread.interrupt(), 218

ThreadLocal, 215

Thread.run(), 44

@ThreadSafe, 9092

throw, 146147

Throwable, 123125

Time-of-check, time-of-use (TOCTOU) race condition

assumptions about file creation, 189190

file identification, 99, 103105

prevention with state testing, 97

Time values, 3133

TIMED_WAITING, 219

Tokenization, 224

Tools, xvii

transient, 158

true, 97

Trusted code, 252253

try-catch block, 123124

try-catch-finally block, 148150

Try to gracefully recover from system errors, 123125

try-with-resources statement, 148151

Types

declaring variables separately, 135137

misuse of overloaded methods to differentiate between, 231233

for second and third operands in conditional expressions, 153157

U

Unchecked warnings, 8284

Understand how escape characters are interpreted when strings are loaded, 228231

Understand the differences between bitwise and logical operators, 225228

Understandability. See Program understandability

Unencrypted sensitive information, 59

Unicode characters, 167168

@Unique("return"), 9495

Unmodifiable interfaces, 85

Unmodifiable wrappers, 911, 238

UnsupportedOperationException, 1011

Untrusted code

defined, 253

do not expose methods that use reduced-security checks to, 5664

do not let misuse privileges of callback methods, 7277

do not rely on methods that can be overridden by, 4450

Untrusted method parameters, 3134

Unused values, 201

updateNode(), 9798

Uploads, 1316

Use braces for body of if, for, or while statement, 178180

Use comments consistently and in readable fashion, 196198

Use exceptions only for exceptional conditions, 146148

Use meaningful symbolic constants to represent literal values in program logic, 138142

Use parentheses for precedence of operation, 186188

Use same type for second and third operands in conditional expressions, 153157

Use serialization methods writeUnshared() and readUnshared() with care, 239243

Use try-with-resources statement to safely handle closeable resources, 148151

User credentials

preventing LDAP injection, 29

preventing XPath injection, 2427

storing passwords using hash functions, 3742

storing unencrypted sensitive information, 59

User-defined exceptions, 121123

UserLookupCallBack, 7377

util, xvi

V

Validated arguments, 1113

ValidateOutput, 1719

validateValue(), 3132

Values

detect and remove superfluous, 198202

meaningful symbolic constants to represent literal, 138142

null. See null values

provide feedback about resulting method, 9699

Variable arity (varargs) types

avoid ambiguous overloading of, 171173

compile-time type checking of, 112115

Variables

do not declare more than one per declaration, 134137

documenting locking policies, 9294

encoding relationships in constant definitions, 142143

minimize scope of, 8082

minimize scope of @SuppressWarnings, 82

setting local reference to null, 243244

shadowing, 133134

Vector, 159

Versions, 116117

volatile

defined, 253

providing synchronization semantics, 217218

safe publication guarantee and, 209216

Vulnerability, 253

W

Wait-notify protocols, 9596

WAITING, 219220

Warnings, 8284

Weak cryptographic algorithms, 3637

while

assignments in conditional expressions, 175

do not place semicolon immediately following, 180181

inadvertent wrapping of loop counters, 183186

use braces for, 178180

Whitelisting

output sanitization, 1719

preventing code injection, 21

preventing LDAP injection, 2728, 3031

Widget, 4749

Worker, 4950

Wrappers

avoid in-band error indicators, 174175

inadvertent wrapping of loop counters, 183186

performActionOnFile(), 5152

unmodifiable, 238

unmodifiable for sensitive mutable classes, 911

Write garbage-collection-friendly code, 128130

writeUnshared(), 239243

X

XML documents, 2327

XPath injection, 2327

XQuery, 2527

XSS (Cross-Site Scripting) attacks

output sanitization, 1619

storing unencrypted sensitive information, 56

-XX:+DisableExplicitGC, 130

-XX:ExplicitGCInvokedConcurrent, 130

Y

yeild(), 216220

Younger generation, 129

Z

Zadegan, Bryant, 204

Zune 30, 203204

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.74.55