npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-safe

v1.0.2

Published

Enhance the security of your Express applications with built-in protection against common web vulnerabilities such as XSS, SQL injection, and clickjacking.

Downloads

552

Readme

中文 | English

express-safe 安全中间件

express-safe通过阻止包含某些关键字和模式的请求来增强你的 Express 应用程序的安全性。这些关键字和模式常用于 SQL 注入攻击、XSS 攻击、防止点击劫持方法和其他恶意活动。

安全逻辑

中间件函数包含以下安全逻辑:

  • 阻止包含 SQL 注入攻击模式的请求。
  • 阻止包含 XSS 攻击模式的请求。
  • 阻止包含其他恶意模式的请求。

安装

你可以通过 npm 安装此包:

npm install express-safe --save

使用方法

要在你的 Express 应用程序中使用此中间件,请简单地引入它并像使用其他中间件一样使用:

const express = require('express');
const safe = require('express-safe');

const app = express();

//全部参数
app.use(safe({
  keywords: ['<script>', 'alert', 'onerror'], // 新增自定义关键词
  sendText: "Access is denied.", // 阻止请求时返回的文本,默认为 "Access is denied."
  frameOption: 'SAMEORIGIN' // 防止点击劫持的方法,默认为 SAMEORIGIN
}));

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(3000, () => {
  console.log('服务器运行在 <http://localhost:3000>');
});

自定义关键词

你可以通过传递一个配置对象来自定义被阻止的关键字和模式:

const express = require('express');
const safe = require('express-safe');

const app = express();

//全局拦截
app.use(safe({
  keywords: ['.zip', '.sql']
}));

//局部拦截
app.get('/',safe(), (req, res) => {
  res.send('Hello World!');
});

app.listen(3000, () => {
  console.log('服务器运行在 http://localhost:3000');
});

注意事项

  • 请确保在使用此中间件时,它放置在所有其他中间件之前,以确保在处理请求之前应用安全逻辑。
  • 此中间件仅提供基本的安全防护,你可能需要根据你的应用程序的具体需求进行进一步的定制和增强。

贡献

如果你有任何改进意见或想要贡献代码,请邮箱[email protected]

作者开源项目

  • ChanCMS——基于Chanjs开发的cms内容管理系统。一个用于记录Express应用程序请求的中间件。
  • Chanjs——基于express+mysql纯js研发的轻量级多模块mvc框架。
  • Saduocss——一个轻量级原子类css框架。

许可证

此项目采用 MIT 许可证。