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

ferds-security

v1.0.1

Published

The Ferds-Security contains methods that help you create a secure application, processing input data for security.

Downloads

4

Readme

Ferds Security

The Ferds Security contains methods that help you create a secure application, processing input data for security. Ferds Security has several functions to support your security such as :

  • Cross Site Scripting prevention filter, which looks for commonly used techniques to trigger JavaScript or other types of code that attempt to hijack cookies or do other malicious things. If anything disallowed is encountered it is rendered safe by converting the data to character entities.
  • Escapes special characters in a string for use in an SQL statement

Features

Now, let’s describe the features:

  • Cross Site Scripting prevention filter.
  • SQL escape string
  • Password Strength Meter

Installation

$ npm install ferds-security

Usages

Escape String

Escaping a string means to reduce ambiguity in quotes (and other characters) used in that string. For instance, when you're defining a string, you typically surround it in either double quotes or single quotes:

"Hello World."

Now I have ambiguity - the interpreter doesn't know where my string ends. If I want to keep my double quotes, I have a couple options. I could use single quotes around my string:

'Hello "World."'

Or I can escape my quotes:

"Hello \"World.\""

Any quote that is preceded by a slash is escaped, and understood to be part of the value of the string.

If you using Ferds Security, the usage of escape string will be very simple like this :

var text1 = "Hello \"World.\"";
var text2 = 'Hello "World."';
var text3 = "Hello World.";

var escape_text1 = security.escape_string( text1 );
var escape_text2 = security.escape_string( text2 );
var escape_text3 = security.escape_string( text3 );

console.log( escape_text1 );
console.log( escape_text2 );
console.log( escape_text3 );

The results will be like this :

Hello \"World.\"
Hello \"World.\"
Hello World.

Password Strength Meter

"No system is totally secure...", Chris Hoofnagle

If we read the that's quote, yes, that's right quote. But, we can set a small prevention for attacker with great password. You can use password_strength_meter function to give you information about the strength of the password. The function will be simple like this :

var strength_password1 = security.password_strength_meter( "ABCDZ" );
var strength_password2 = security.password_strength_meter( "ABCDZ!@#123_~KWJFKWJFKJWFK*@&$(@&" );

console.log( "The strength of the Password 1 is " + strength_password1 );
console.log( "The strength of the Password 2 is " + strength_password2 );

Results :

The strength of the Password 1 is 25
The strength of the Password 2 is 100

This is some criteria of strength of your password :

| Score | Description | | ------------- |:-------------:| | 0 - 25 | Very Bad | | 26-50 | Weak | | 51-75 | Good | | 76-100 | Strong |

Sanitize

To prevent the Cross Site Scripting, you can use three ways :

  • Escaping
  • Validating Input (You can use Ferds Validator to creating simple validation with various function methods.)
  • Sanitizing

Okay, now we will try to prevent Cross Site Scripting with Sanitize function. Examples of simple use :

var security = require( 'ferds-security' );
var text = '<script>alert("XXX");</script>';
var sanitize_text = security.sanitizer( text );

console.log( sanitize_text );

The results will be like this :

&lt;script&gt;alert(&quot;XXX&quot;);&lt;&#x2F;script&gt;

Author

Ferdinand [[email protected]]