Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 33 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,47 @@
The [GitBook][8] version of this book, for easy online reading, can be found here:
[https://checkmarx.gitbooks.io/go-scp][9]
您可以按以下格式下载本书:[PDF][12]、[Mobi][13] 和
[ePub] [14]。

The book can be downloaded in PDF, Mobi and ePub formats here:
[https://www.gitbook.com/book/checkmarx/go-scp][10]
# 介绍

# Introduction
Go 语言 - Web 应用程序安全编码实践是为使用 [Go 编程语言][1] 并旨在将其用于 Web 开发的任何人编写的指南。

Go Language - Web Application Secure Coding Practices is a guide written for
anyone who is using the [Go Programming Language][1] and aims to use it for web
development.
本书是 [Checkmarx 安全研究团队][2] 的合作成果,它遵循 [OWASP 安全编码实践 - 快速参考指南 v2(稳定)][3] 版本。

This book is collaborative effort of [Checkmarx Security Research Team][2] and
it follows the
[OWASP Secure Coding Practices - Quick Reference Guide v2 (stable)][3] release.
本书的主要目标是帮助开发人员避免常见错误,同时通过“实践方法”学习新的编程语言。这本书提供了关于“如何安全地做到这一点”的详细信息,展示了开发过程中可能出现的安全问题。

The main goal of this book is to help developers avoid common mistakes while at
the same time, learning a new programming language through a
"hands-on approach".
This book provides a good level of detail on "how to do it securely" showing
what kind of security problems could arise during development.
## 本书的读者

## About Checkmarx
Go Secure Coding Practices Guide 的主要受众是开发人员,尤其是那些以前有其他编程语言经验的开发人员。

Checkmarx is an Application Security software company, whose mission is to
provide enterprise organizations with application security testing products
and services that empower developers to deliver secure applications. Amongst
the company's 1,000 customers are five of the world's top 10 software vendors,
four of the top American banks, and many Fortune 500 and government
organizations, including SAP, Samsung and Salesforce.com.
对于第一次学习编程,已经完成[Go 之旅][8] 的人来说,本书也是一个很好的参考。

For more information about Checkmarx, visit [http://www.checkmarx.com][2]
or follow us on Twitter: [@checkmarx][7]
[Summary](src/SUMMARY.md)

## About OWASP Secure Coding Practices
## 你会学到什么

The [Secure Coding Practices Quick Reference Guide][3] is an [OWASP][4] - Open
Web Application Security Project. It is a "_technology agnostic set of
general software security coding practices, in a comprehensive checklist
format, that can be integrated into the development lifecycle_" ([source][3]).
本书逐个主题地介绍了 [OWASP 安全编码实践指南 [3],提供使用 Go 的示例和建议,以帮助开发人员避免常见错误和陷阱。

[OWASP][4] itself is "_an open community dedicated to enabling organizations to
conceive, develop, acquire, operate, and maintain applications that can be
trusted. All of the OWASP tools, documents, forums, and chapters are free and
open to anyone interested in improving application security_" ([source][5]).
阅读本书后,您将更有信心开发安全的 Go 应用程序。

## How To Contribute
## 关于 OWASP 安全编码实践

This book was created using a few open source tools.
If you're curious about how we built it from scratch, read the
[How To contribute section][6].
本书改编自 The [Secure Coding Practices Quick Reference Guide][3], an [OWASP][4] - Open Web Application Security Project 中的 Go 语言。它是“_技术不可知的一组通用软件安全编码实践,采用综合清单格式,可以集成到开发生命周期_”([来源][3])。

[OWASP][4] 本身就是“_一个开放社区,致力于使组织能够构思、开发、获取、操作和维护可信任的应用程序。所有 OWASP 工具、文档、论坛和章节都是免费的,对任何对提高应用程序安全性感兴趣的人_”([来源 [5])。

## 如何贡献

本书是使用一些开源工具创建的。如果您对我们如何从头开始构建它感到好奇,请阅读 [如何贡献部分][6]。

## 译者说
翻译的不是很好,请大家多多指教。 欢迎 PR

## License

本文档根据知识共享署名-相同方式共享 4.0 国际许可 (CC BY-SA 4.0) 发布。对于任何重复使用或分发,您必须向他人明确本作品的许可条款 [https://creativecommons.org/licenses/by-sa/4.0/][11]

[1]: https://golang.org
[2]: https://www.checkmarx.com
[2]: http://chkmrx.co/2sffXFr
[3]: https://www.owasp.org/index.php/OWASP_Secure_Coding_Practices_-_Quick_Reference_Guide
[4]: https://www.owasp.org
[5]: https://www.owasp.org/index.php/About_OWASP
Expand All @@ -60,3 +50,7 @@ If you're curious about how we built it from scratch, read the
[8]: https://www.gitbook.com/
[9]: https://checkmarx.gitbooks.io/go-scp/
[10]: https://www.gitbook.com/book/checkmarx/go-scp/
[11]: https://creativecommons.org/licenses/by-sa/4.0/
[12]: dist/go-webapp-scp.pdf
[13]: dist/go-webapp-scp.mobi
[14]: dist/go-webapp-scp.epub
72 changes: 36 additions & 36 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
# Introduction
您可以按以下格式下载本书:[PDF][12]、[Mobi][13] 和
[ePub] [14]。

Go Language - Web Application Secure Coding Practices is a guide written for
anyone who is using the [Go Programming Language][1] and aims to use it for web
development.
# 介绍

This book is collaborative effort of [Checkmarx Security Research Team][2] and
it follows the
[OWASP Secure Coding Practices - Quick Reference Guide v2 (stable)][3] release.
Go 语言 - Web 应用程序安全编码实践是为使用 [Go 编程语言][1] 并旨在将其用于 Web 开发的任何人编写的指南。

The main goal of this book is to help developers avoid common mistakes while at
the same time, learning a new programming language through a
"hands-on approach".
This book provides a good level of detail on "how to do it securely" showing
what kind of security problems could arise during development.
本书是 [Checkmarx 安全研究团队][2] 的合作成果,它遵循 [OWASP 安全编码实践 - 快速参考指南 v2(稳定)][3] 版本。

## About Checkmarx
本书的主要目标是帮助开发人员避免常见错误,同时通过“实践方法”学习新的编程语言。这本书提供了关于“如何安全地做到这一点”的详细信息,展示了开发过程中可能出现的安全问题。

Checkmarx is an Application Security software company, whose mission is to
provide enterprise organizations with application security testing products
and services that empower developers to deliver secure applications. Amongst
the company's 1,000 customers are five of the world's top 10 software vendors,
four of the top American banks, and many Fortune 500 and government
organizations, including SAP, Samsung and Salesforce.com.
## 本书的读者

For more information about Checkmarx, visit [http://www.checkmarx.com][2]
or follow us on Twitter: [@checkmarx][7]
Go Secure Coding Practices Guide 的主要受众是开发人员,尤其是那些以前有其他编程语言经验的开发人员。

## About OWASP Secure Coding Practices
对于第一次学习编程,已经完成[Go 之旅][8] 的人来说,本书也是一个很好的参考。

The [Secure Coding Practices Quick Reference Guide][3] is an [OWASP][4] - Open
Web Application Security Project. It is a "_technology agnostic set of
general software security coding practices, in a comprehensive checklist
format, that can be integrated into the development lifecycle_" ([source][3]).
[Summary](SUMMARY.md)

[OWASP][4] itself is "_an open community dedicated to enabling organizations to
conceive, develop, acquire, operate, and maintain applications that can be
trusted. All of the OWASP tools, documents, forums, and chapters are free and
open to anyone interested in improving application security_" ([source][5]).
## 你会学到什么

## How To Contribute
本书逐个主题地介绍了 [OWASP 安全编码实践指南 [3],提供使用 Go 的示例和建议,以帮助开发人员避免常见错误和陷阱。

This book was created using a few open source tools.
If you're curious about how we built it from scratch, read the
[How To contribute section][6].
阅读本书后,您将更有信心开发安全的 Go 应用程序。

## 关于 OWASP 安全编码实践

本书改编自 The [Secure Coding Practices Quick Reference Guide][3], an [OWASP][4] - Open Web Application Security Project 中的 Go 语言。它是“_技术不可知的一组通用软件安全编码实践,采用综合清单格式,可以集成到开发生命周期_”([来源][3])。

[OWASP][4] 本身就是“_一个开放社区,致力于使组织能够构思、开发、获取、操作和维护可信任的应用程序。所有 OWASP 工具、文档、论坛和章节都是免费的,对任何对提高应用程序安全性感兴趣的人_”([来源 [5])。

## 如何贡献

本书是使用一些开源工具创建的。如果您对我们如何从头开始构建它感到好奇,请阅读 [如何贡献部分][6]。

## License

本文档根据知识共享署名-相同方式共享 4.0 国际许可 (CC BY-SA 4.0) 发布。对于任何重复使用或分发,您必须向他人明确本作品的许可条款 [https://creativecommons.org/licenses/by-sa/4.0/][11]

[1]: https://golang.org
[2]: https://www.checkmarx.com
[2]: http://chkmrx.co/2sffXFr
[3]: https://www.owasp.org/index.php/OWASP_Secure_Coding_Practices_-_Quick_Reference_Guide
[4]: https://www.owasp.org
[5]: https://www.owasp.org/index.php/About_OWASP
[6]: /howto-contribute.md
[6]: src/howto-contribute.md
[7]: https://www.twitter.com/checkmarx
[8]: https://www.gitbook.com/
[9]: https://checkmarx.gitbooks.io/go-scp/
[10]: https://www.gitbook.com/book/checkmarx/go-scp/
[11]: https://creativecommons.org/licenses/by-sa/4.0/
[12]: dist/go-webapp-scp.pdf
[13]: dist/go-webapp-scp.mobi
[14]: dist/go-webapp-scp.epub
55 changes: 29 additions & 26 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
概述
Summary
=======

* [简介](README.md)
* [输入验证](input-validation/README.md)
* [验证](input-validation/validation.md)
* [数据清洗](input-validation/sanitization.md)
* [输出编码](output-encoding/README.md)
* [XSS](output-encoding/cross-site-scripting.md)
* [SQL注入](output-encoding/sql-injection.md)
* [Authentication and Password Management](authentication-password-management/README.md)
* [Communicating authentication data](authentication-password-management/communicating-authentication-data.md)
* [Validation and Storage](authentication-password-management/validation-and-storage.md)
* [Password policies](authentication-password-management/password-policies.md)
* [Other guidelines](authentication-password-management/other-guidelines.md)
* [Session Management](session-management/README.md)
* [Access Control](access-control/README.md)
* [Cryptographic Practices](cryptographic-practices/README.md)
* [Pseudo-Random Generators](cryptographic-practices/pseudo-random-generators.md)
* [Error Handling and Logging](error-handling-logging/README.md)
* [Error Handling](error-handling-logging/error-handling.md)
* [Logging](error-handling-logging/logging.md)
* [Data Protection](data-protection/README.md)
* [Communication Security](communication-security/README.md)
* [XSS - Cross-Site Scripting](output-encoding/cross-site-scripting.md)
* [SQL Injection](output-encoding/sql-injection.md)
* [身份验证和密码管理](authentication-password-management/README.md)
* [通信认证数据](authentication-password-management/communicating-authentication-data.md)
* [验证和存储认证数据](authentication-password-management/validation-and-storage.md)
* [密码策略](authentication-password-management/password-policies.md)
* [其他指南](authentication-password-management/other-guidelines.md)
* [会话管理](session-management/README.md)
* [访问控制](access-control/README.md)
* [密码实践](cryptographic-practices/README.md)
* [伪随机生成器](cryptographic-practices/pseudo-random-generators.md)
* [日志与错误处理](error-handling-logging/README.md)
* [错误处理](error-handling-logging/error-handling.md)
* [日志](error-handling-logging/logging.md)
* [数据保护](data-protection/README.md)
* [通信安全](communication-security/README.md)
* [HTTP/TLS](communication-security/http-tls.md)
* [WebSockets](communication-security/websockets.md)
* [System Configuration](system-configuration/README.md)
* [Database Security](database-security/README.md)
* [Connections](database-security/connections.md)
* [Authentication](database-security/authentication.md)
* [Parameterized Queries](database-security/parameterized-queries.md)
* [Stored Procedures](database-security/stored-procedures.md)
* [File Management](file-management/README.md)
* [Memory Management](memory-management/README.md)
* [General Coding Practices](general-coding-practices.md)
* [系统配置](system-configuration/README.md)
* [数据库安全](database-security/README.md)
* [链接](database-security/connections.md)
* [认证](database-security/authentication.md)
* [参数化查询](database-security/parameterized-queries.md)
* [存储过程](database-security/stored-procedures.md)
* [文件管理](file-management/README.md)
* [内存管理](memory-management/README.md)
* General Coding Practices
* [Cross-Site Request Forgery](general-coding-practices/cross-site-request-forgery.md)
* [Regular Expressions](general-coding-practices/regular-expressions.md)
* [How To Contribute](howto-contribute.md)
* [Final Notes](final-notes.md)
18 changes: 18 additions & 0 deletions src/authentication-password-management/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
身份验证和密码管理
======================================

[OWASP 安全编码实践][1]是一份有价值的文档,可帮助程序员验证在项目实施过程中是否遵循了所有最佳实践。身份验证和密码管理是任何系统的关键部分,从用户注册到凭据存储、密码重置和私有资源访问,都对它们进行了详细介绍。

为了获得更深入的细节一些指南可能会被分组。此外,还提供了源代码示例来说明这些主题。

## 经验法则

让我们从经验法则开始:**所有身份验证控制必须在受信任的系统上强制执行**,这通常是运行应用程序后端的服务器。

为了系统的简单性和减少故障点,您应该使用标准和经过测试的身份验证服务。通常框架已经有这样的模块,并且鼓励您使用它们,因为它们被许多人作为集中式身份验证机制开发、维护和使用。尽管如此,您应该**仔细检查代码以确保它不受任何恶意代码的影响**,并确保它遵循最佳实践。

需要身份验证的资源不应自己做验证。相反,应该使用**redirection to and from the central authentication control**。小心处理重定向:您应该只重定向到本地和 / 或安全资源。

身份验证不应仅由给用户使用,也应由您自己在需要**连接到涉及敏感信息或功能的外部系统**时也应该要验证身份。例如,**用于访问应用程序外部服务的身份验证凭据应加密并存储在受信任系统(例如服务器)上的受保护位置。凭据放在源码里是不安全的**。

[1]: https://www.owasp.org/index.php/OWASP_Secure_Coding_Practices_-_Quick_Reference_Guide
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
通信认证数据
==================================

在本节中,“通信”更加广义,包括用户体验 (UX) 和客户端-服务器通信。

不仅**password 条目应该在用户的屏幕上被隐藏**是正确的,而且**remember me 功能应该被禁用**也是如此。

你可以通过使用带有 `type="password"` 的输入框,并将 `autocomplete` 属性设置为 `off`[^1] 来完成这两项操作。

```html
<input type="password" name="passwd" autocomplete="off" />
```

身份验证凭据应仅通过加密连接 (HTTPS) 发送。电子邮件重置相关的临时密码可能可以不用 HTTPS 。

通常请求的 URL 由 HTTP 服务器(`access_log`)记录,其中包括查询字符串。为防止身份验证凭据泄漏到日志里面,应使用 HTTP `POST` 方法将数据发送到服务器。

```text
xxx.xxx.xxx.xxx - - [27/Feb/2017:01:55:09 +0000] "GET /?username=user&password=70pS3cure/oassw0rd HTTP/1.1" 200 235 "-" "Mozilla/5.0 (X11) ; Fedora; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0"
```

一个设计良好的用于身份验证的 HTML 表单如下所示:

```html
<form method="post" action="https://somedomain.com/user/signin" autocomplete="off">
<input type="hidden" name="csrf" value="CSRF-TOKEN" />

<label>用户名 <input type="text" name="username" /></label>
<label>密码 <input type="password" name="password" /></label>

<input type="submit" value="提交" />
</form>
```

在处理身份验证错误时,你的应用程序不应透露身份验证数据的哪一部分不正确。使用“无效的用户名和(或)密码”来替代“无效的用户名”或“无效的密码”:

```html
<form method="post" action="https://somedomain.com/user/signin" autocomplete="off">
<input type="hidden" name="csrf" value="CSRF-TOKEN" />

<div class="error">
<p>无效的用户名和(或)密码</p>
</div>

<label>用户名 <input type="text" name="username" /></label>
<label>密码 <input type="password" name="password" /></label>

<input type="submit" value="提交" />
</form>
```

如果不这样做会暴露的信息如下:

* 谁已经注册过了:“无效的密码”表示用户名存在。
* 你的系统如何工作:“无效的密码”可能会揭示你的应用程序如何工作,首先查询数据库中的“用户名”,然后比较内存中的密码。

在[验证和存储部分][5]中提供了如何执行身份验证数据验证(和存储)的示例。

成功登录后,应通知用户上次成功或不成功的访问日期/时间,以便他可以检测和报告可疑活动。有关日志记录的更多信息可以在文档的 [`错误处理和日志记录`][4] 部分中找到。此外,还建议在检查密码时使用恒定时间比较功能,以防止计时攻击。后者包括分析具有不同输入的多个请求之间的时间差异。在这种情况下,“记录 == 密码”形式的标准比较将在第一个不匹配的字符处返回 false。提交的密码越接近,响应时间越长。通过利用这一点,攻击者可以猜测密码。请注意,即使记录不存在,我们也总是强制执行带有空值的 `subtle.ConstantTimeCompare` 以将其与用户输入进行比较。

---

[^1]: [How to Turn Off Form Autocompletion][1], Mozilla Developer Network
[^2]: [Log Files][2], Apache Documentation
[^3]: [log_format][3], Nginx log_module "log_format" directive

[1]: https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
[2]: https://httpd.apache.org/docs/1.3/logs.html#accesslog
[3]: http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
[4]: ../error-handling-logging/logging.md
[5]: ./validation-and-storage.md#storing-password-securely-the-practice
Loading