Java编码指南:编写安全可靠程序的75条建议(英文版)

978-7-115-40401-5
作者: 【美】Fred Long(弗雷德•朗) Dhruv Mohindra(德鲁•莫欣达) Robert C. Seacord(罗伯特 C.西科德) Dean F. Sutherland(迪恩 F.萨瑟兰) David Svoboda(大卫•斯沃博达)
译者: 无
编辑: 杨海玲
分类: Java

图书目录:

目录

Chapter 1 Security / 安全 1

1. Limit the lifetime of sensitive data 2

限制敏感数据的生命周期

2. Do not store unencrypted sensitive information on the client side 5

不要在客户端存储未经加密的敏感数据

3. Provide sensitive mutable classes with unmodifiable wrappers 9

为敏感可变类提供不可修改的包装器

4. Ensure that security-sensitive methods are called with validated arguments 11

确保安全敏感方法被调用时参数经过验证

5. Prevent arbitrary file upload 13

防止任意文件上传

6. Properly encode or escape output 16

正确地编码或转义输出

7. Prevent code injection 20

防止代码注入

8. Prevent XPath injection 23

防止XPath注入

9. Prevent LDAP injection 27

防止LDAP注入

10. Do not use the clone() method to copy untrusted method parameters 31

不要使用clone()方法来复制不可信的方法参数

11. Do not use Object.equals() to compare cryptographic keys 34

不要使用Object.equals()来比较密钥

12. Do not use insecure or weak cryptographic algorithms 36

不要使用不安全的弱加密算法

13. Store passwords using a hash function 37

使用散列函数存储密码

14. Ensure that SecureRandom is properly seeded 42

确保SecureRandom正确地选择随机数种子

15. Do not rely on methods that can be overridden by untrusted code 44

不要依赖可以被不可信代码覆写的方法

16. Avoid granting excess privileges 50

避免授予过多特权

17. Minimize privileged code 54

**小化特权代码

18. Do not expose methods that use reduced-security checks to untrusted code 56

不要将使用降低安全性检查的方法暴露给不可信代码

19. Define custom security permissions for fine-grained security 64

对细粒度的安全定义自定义安全权限

20. Create a secure sandbox using a security manager 67

使用安全管理器创建一个安全的沙盒

21. Do not let untrusted code misuse privileges of callback methods 72

不要让不可信代码误用回调方法的特权

Chapter 2 Defensive Programming / 防御式编程 79

22. Minimize the scope of variables 80

**小化变量的作用域

23. Minimize the scope of the @SuppressWarnings annotation 82

**小化@SuppressWarnings注解的作用域

24. Minimize the accessibility of classes and their members 84

**小化类及其成员的可访问性

25. Document thread-safety and use annotations where applicable 89

文档化代码的线程安全性

26. Always provide feedback about the resulting value of a method 96

为方法的结果值提供反馈

27. Identify files using multiple file attributes 99

使用多个文件属性识别文件

28. Do not attach significance to the ordinal associated with an enum 106

不要赋予枚举常量的序号任何特殊意义

29. Be aware of numeric promotion behavior 108

注意数字提升行为

30. Enable compile-time type checking of variable arity parameter types 112

对可变参数的类型做编译时类型检查

31. Do not apply public final to constants whose value might change in later releases 115

不要把其值在以后版本里可能会发生变化的常量设置为public final

32. Avoid cyclic dependencies between packages 118

避免包之间的循环依赖

33. Prefer user-defined exceptions over more general exception types 121

使用用户自定义的异常而非宽泛的异常类型

34. Try to gracefully recover from system errors 123

尽量从系统错误中优雅恢复

35. Carefully design interfaces before releasing them 125

布接口前请谨慎设计

36. Write garbage collection–friendly code 128

编写对垃圾回收机制友好的代码

Chapter 3 Reliability / 可靠性 131

37. Do not shadow or obscure identifiers in subscopes 132

不要在子作用域里遮蔽或者掩盖标识符

38. Do not declare more than one variable per declaration 134

不要在一个声明里声明多个变量

39. Use meaningful symbolic constantsto represent literal values in program logic 138

在程序逻辑中用有意义的符号常量代表文字值

40. Properly encode relationships in constant definitions 142

在常量定义中恰当地表示相互之间的关系

41. Return an empty array or collection instead of a null value for methods that return an array or collection 143

对于返回数组或者集合的方法,用返回一个空数组或者集合来替代返回一个空值

42. Use exceptions only for exceptional conditions 146

只在异常的情况下使用异常

43. Use a try-with-resources statement to safely handle closeable resources 148

使用try-with-resources语句安全处理可关闭的资源

44. Do not use assertions to verify the absence of runtime errors 151

不要使用断言来验证不存在的运行时错误

45. Use the same type for the second and third operands in conditional expressions 153

在条件表达式中,第 二和第三个操作数应使用相同类型

46. Do not serialize direct handles to system resources 157

不要序列化直接指向系统资源的句柄

47. Prefer using iterators over enumerations 159

更倾向于使用迭代器而不是枚举

48. Do not use direct buffers for short-lived, infrequently used objects 162

对于短生存周期、不常用的对象不要使用直接缓冲区

49. Remove short-lived objects from long-lived containe

详情

本书把那些不必列入Java安全编码标准但是同样会导致系统不可靠或不安全的Java编码实践整理了出来,并为这些糟糕的实践提供了相应的文档和警告,以及合规解决方案。读者可以将本书作为Java安全方面的工具书,根据自己的需要找到自己感兴趣的规则进行阅读和理解,也可以系统地了解Java安全规则,增强对Java安全特性、语言使用、运行环境特性的理解。

图书摘要

相关图书

Effective Java中文版(原书第3版)
Effective Java中文版(原书第3版)
Java核心技术速学版(第3版)
Java核心技术速学版(第3版)
Java编程动手学
Java编程动手学
Java研发自测入门与进阶
Java研发自测入门与进阶
Java开发坑点解析:从根因分析到最佳实践
Java开发坑点解析:从根因分析到最佳实践
Java EE企业级应用开发实战(Spring Boot+Vue+Element)
Java EE企业级应用开发实战(Spring Boot+Vue+Element)

相关文章

相关课程