@laosdirg/security

A bunch of helpers for securing javascript applications

@laosdirg/security

A bunch of helpers for securing javascript applications

------ -
  -------------
  ---------------
  --------------
  -----------
  ------------
- ---- ------------------------

-------- --------------- --------- -
  -- ------- -------- ----------- ---- -------
  ----- - --------- ----------------- - - -------------
  -- ------ ------ --------
  ----- ------------ - --------------------------------
  -- ------- ---- -- ------- ---- ------ --------
  ------------- --------- ------------ ---
  -- ---------- --- -- ---- ----- ----- --- -----
  ------ -------------- ----------
-

-------- -------------- --------- -
  -- ------- -------- ----------- ---- -------
  ----- - --------- ----------------- - - -------------
  -- ----- ------------- ---- ---- -------
  ----- - ------- ------------ - - ---------- -------- ---
  -- ------ -------- ------- ------ ----
  -- ----------------------------- ------------------- -
    ----- --- ----------------------
  -
  -- -------- ----- -----
  ----- - ------ --------- ------------ - - ----------------
  -- ----- ---- ------ -------- -- -------- --- ---- ---------
  -------------- --------- ------------- ------ ---
  -- ---- -------- ----- -- ----
  ------------------------ -------
-

-------- -------------------- --------- -
  -- ------- ----- ----- ------- ------------- ------- -----
  ----- - ----- - - ----------------
  -- ----- ----- ---- -------- --- -------- --------
  ----- - --------- ----------------- - - ------------------
  -- --- -------- -- ----- ----- ---- -------
  ----- - ------------- ------ - - ----------- -------- ---
  -- ------ --- ----- ----- -- --------
  ----------------------------- ------------------- -
    ----- --- ----------------------
  -
  -- ----- ------------- ---- --- ---- -- --------
  ----- ---- - ---------- ------ ---
  --------------------
-

Installation

- --- ------- ------------------

API

Passwords

Passwords are be hashed with a salt, and stored with the parameters that generated the password.

hashPassword(plaintext: string)

Returns string hashed password.

verifyPassword(hash: string, plaintext: string)

Returns boolean whether verification succeeded.

Tokens (split tokens)

Tokens have many uses: user sessions, password recovery emails, etc., usually they are provided upon presenting some other kind of credentials like a username and password.

However, tokens need to be treated like passwords. If an attacker gains with read-only access to your token database and they are stored as-is, the attacker can steal and use all of your tokens.

Following best practices from paragonie, our approach splits tokens into a username-like and password-like part, and hashes the password-like part. The entire unhashed token can be sent to the user, but the unhashed token should never be stored in your database.

The selector is to prevent leaking timing information.

generateToken()

Returns { token: string, selector: string, verifierHash: string } split token.

splitToken(token: string)

Returns { selector: string, verifierPlaintext: string} selector and verifier in dict.

verifyToken(hash: string, plaintext: string)

Returns boolean whether verification succeeded.

Usefull tools

  • helmet for setting various headers in express apps.
  • zxcvbn estimating password strength (display this to users during signup)

Additional reading

How to Safely Store Your Users' Passwords in 2016

https://paragonie.com/blog/2016/02/how-safely-store-password-in-2016

Implementing password reset

https://paragonie.com/blog/2016/09/untangling-forget-me-knot-secure-account-recovery-made-simple

TL;DR:

  • DO:
    • Make automated password resets optional, and opt-in
    • Send a short-lived URL to their email address which contains a random token (generated by a CSPRNG)
    • Use a split-token strategy to mitigate side-channels and database leaks
    • Allow users to upload a PGP public key, and if it's available, use it encrypt the recovery URL
  • DO NOT:
    • Email the user their old password
    • Change the user's password for them and email them the new one
    • Rely on security questions/answers, which most attackers can guess for their targets

Additional security

Cross-Site Scripting (XSS)

Cross-Site Request Forgery

Cross-Site Request Forgery (CSRF/XSRF) is a type of attack that occurs when a malicious web site, email, blog, instant message, or program causes a user's web browser to perform an unwanted action on a trusted site for which the user is currently authenticated. The impact of a successful CSRF attack is limited to the capabilities exposed by the vulnerable application. For example, this attack could result in a transfer of funds, changing a password, or purchasing an item in the user's context. In effect, CSRF attacks are used by an attacker to make a target system perform a function via the target's browser without knowledge of the target user, at least until the unauthorized transaction has been committed.

Defense

It is imperative that no XSS vulnerabilities are present to ensure that CSRF defenses can't be circumvented.

The synchronizer token pattern requires the generating of random "challenge" tokens that are associated with the user's current session. These challenge tokens are then inserted within the HTML forms and links associated with sensitive server-side operations. When the user wishes to invoke these sensitive operations, the HTTP request should include this challenge token. It is then the responsibility of the server application to verify the existence and correctness of this token. By including a challenge token with each request, the developer has a strong control to verify that the user actually intended to submit the desired requests. Inclusion of a required security token in HTTP requests associated with sensitive business functions helps mitigate CSRF attacks as successful exploitation assumes the attacker knows the randomly generated token for the target victim's session. This is analogous to the attacker being able to guess the target victim's session identifier.

License

MIT

HomePage

https://github.com/laosdirg/security#readme

Repository

git+https://github.com/laosdirg/security.git

来源:JavaScript中文网 ,转载请联系管理员! 本文地址:https://www.javascriptcn.com/post/6005680581e8991b448e4292


猜你喜欢

  • npm 包 nueah-net 使用教程

    npm 是一个非常重要的 Node.js 包管理器,可以通过它来方便地安装和管理各种 Node.js 模块和工具。这次我们要介绍的是一个 npm 包,名为 nueah-net。

    3 年前
  • npm 包 nueah-process 使用教程

    简介 nueah-process 是一个包含多个前端工具方法的 npm 包,可以帮助前端开发者更轻松地处理数据、字符串、时间等。本文将详细介绍如何使用这个 npm 包,在实践中掌握这些工具方法。

    3 年前
  • npm 包 @i2/runonpage 使用教程

    前言 在现代的 Web 开发中,前端技术与日俱增,我们的代码也逐渐变得越来越复杂。为了更高效地管理和组织代码,我们常常会使用各种工具和框架。在这些工具和框架的背后,有一个我们常常忽略的神秘的存在,那就...

    3 年前
  • npm 包 lluchmk-ng2-table 使用教程

    在前端开发中,表格是一个非常常见的组件。为了简化表格组件的开发和使用,我们可以使用现成的开源组件,其中 lluchmk-ng2-table 就是一个非常不错的选择。

    3 年前
  • npm 包 rollup-plugin-strip-prop-types 使用教程

    前言 在前端开发中,我们使用许多工具和技术来提高我们的开发效率。npm 包是其中一种非常重要的工具,它提供了许多好用的库和工具,让我们的开发变得更加简单。其中,rollup-plugin-strip-...

    3 年前
  • npm 包 Platzom-mtn 使用教程

    什么是 Platzom-mtn Platzom-mtn 是一个前端开发工具,包含多种字符串转换方法,可用于对字符串进行处理和操作。 如何安装 Platzom-mtn 要使用 Platzom-mtn,您...

    3 年前
  • npm 包 dfinity-tx 使用教程

    在使用区块链应用程序时,与区块链进行交互的事情之一是在区块链上执行事务。 dfinity-tx 是一个 Node.js 模块,这是与 Dfinity 区块链进行交互的一种方式。

    3 年前
  • npm 包 vue-auto-float-directive 使用教程

    vue-auto-float-directive 是一个 Vue 框架的 npm 包,该包提供了一种简单易用的方式,让页面中的某些元素可以随着用户的滚动而滑动或者固定在页面的某个位置上。

    3 年前
  • npm 包 get-own-property 的使用教程

    简介 get-own-property 是一个 npm 包,用于获取对象的自有属性。它可以帮助前端开发者更方便地处理对象属性。 安装 在终端或命令行窗口中,执行以下命令来安装 get-own-prop...

    3 年前
  • npm 包 kafka-observable 使用教程

    在前端开发中,处理流式数据是一个很常见的场景。Kafka 是一种流式数据平台,它可以处理海量消息并支持高吞吐量和高可靠性,因此在大规模互联网应用中得到了广泛应用。kafka-observable 是一...

    3 年前
  • npm 包 lintworm 使用教程

    什么是 lintworm? lintworm 是一种非常有用的 npm 包,它可以帮助程序员在编写代码时精确地遵循一系列代码风格和规范。lintworm 通过对代码进行一系列的静态分析,来发现代码中可...

    3 年前
  • npm 包 personity-report 使用教程

    介绍 在前端开发中,我们经常会使用各种 npm 包来帮助我们完成任务。其中,personity-report 是一个可以帮助我们生成人格报告的 npm 包,通过分析文本,自动生成一个与文本相关的人格描...

    3 年前
  • npm 包 react-recaptcha-dev 使用教程

    在前端开发中,有些功能需要借助第三方库来实现。recaptcha 是一种反人类行为识别技术,可以在网站提交表单时防止机器人自动提交。如果你使用 React 来开发网站,那么 react-recaptc...

    3 年前
  • npm 包 rollup-plugin-hash 使用教程

    前置知识 在学习 rollup-plugin-hash 之前,你需要具备以下知识: 熟悉 npm 管理包的基本操作 熟悉 Rollup 的基本使用方法 什么是 rollup-plugin-hash...

    3 年前
  • npm 包 thobitcore 使用教程

    介绍 thobitcore 是一个 Node.js 包,用于实现比特币和其他加密货币的钱包和区块链相关应用程序。它是一个高可扩展性的工具,提供了许多先进的功能,包括区块链解析、私钥管理、交易管理等等。

    3 年前
  • npm 包 vue-navigation-plugin 使用教程

    本文将为大家介绍一款名为 vue-navigation-plugin 的 npm 包,它提供了一种方便的方式来实现前端路由的管理和跳转。本文将详细介绍这个包的使用方法以及其背后的技术原理,帮助读者更好...

    3 年前
  • npm 包 @noticeable/remove-markdown 使用教程

    在前端开发中,我们经常需要将 Markdown 格式的文本转换为普通的文本或 HTML 格式,以便在网页中进行展示或处理。而 @noticeable/remove-markdown 是一款 npm 包...

    3 年前
  • npm 包 input-ip 使用教程

    在进行前端开发中,经常需要获取用户的 IP 地址。今天,我们将介绍一个名为 input-ip 的 npm 包,它可以帮助我们简单地获取用户的 IP 地址。 input-ip 如何工作 该 npm 包利...

    3 年前
  • npm 包 cbll 使用教程

    在前端开发中,我们通常需要使用一些第三方开源库来方便我们的开发。其中 Node.js 环境下的包管理工具 npm 可以帮我们快速下载和安装这些第三方库。 在本篇文章中,我们将介绍一个常用的 npm 包...

    3 年前
  • npm 包 homebridge-mqtt-door 使用教程

    随着物联网技术的发展,智能家居设备开始逐渐普及。然而,不同厂商生产的设备使用不同的通信协议,使得设备之间的不兼容问题也逐渐显现出来。为了解决这个问题,MQTT协议应运而生。

    3 年前

相关推荐

    暂无文章