bksanitizers

Quickly Sanitize user data

Usage no npm install needed!

<script type="module">
  import bksanitizers from 'https://cdn.skypack.dev/bksanitizers';
</script>

README

Sanitizers logo

Welcome to BK Sanitizers (BKS)

Welcome

Quickly Sanitize user data

Sanitizers is also called as BK Sanitizers (Baal-Krshna Sanitizers)

Latest release: GitHub release (latest by date)
Info ⇒ BK Sanitizers is a Web Sanitizers written in php


See:
Sanitizers Docs »
Sanitizers Wiki »

Pages ⇒ Report bug(s) β€’ Releases β€’ Request feature β€’ Blog



Twitter Join the chat at https://gitter.im/BaalKrshna/Sanitizers GitHub stars GitHub watchers

Table of contents

Quick Start πŸš€

git clone https://github.com/PuneetGopinath/Sanitizers.git OR gh repo clone PuneetGopinath/Sanitizers

  • Installation πŸ”§

See INSTALL.md file for Installation guide.

  • Usage

Just include the file and Sanitize the user input.

  • Example Usage without composer autoload:
<?php
// Import classes
use Sanitizers\Sanitizers\Sanitizer;

require "src/Sanitizers.php";

// passing `true` in Sanitize class enables exceptions
$sanitizer = new Sanitizer(true);
try {
    echo $sanitizer->sanitize("username", $_GET["username"]);
} catch (Exception $e) {
    echo "Could not Sanitize user input.";
    var_dump($e);
}
?>
  • Example Usage with composer autoload:
<?php
// Import classes
use Sanitizers\Sanitizers\Sanitizer;

require "vendor/autoload.php";

$sanitizer = new Sanitizer(true);
try {
    echo $sanitizer->sanitize("username", $_GET["username"]);
} catch (Exception $e) {
    echo "Could not Sanitize user input.";
    var_dump($e);
}
?>

Status

Join the chat at https://gitter.im/BaalKrshna/Sanitizers FOSSA Status

Workflows

PHP Composer

GitHub

GitHub commit activity GitHub last commit Github Downloads GitHub stars GitHub issues GitHub pull requests GitHub package.json dynamic GitHub release (latest by date) Snyk Vulnerabilities for GitHub Repo GitHub top language GitHub code size in bytes GitHub language count GitHub repo size Maintenance

Packagist

Latest Stable Version PHP Support Latest Unstable Version Total Downloads Monthly Downloads .gitattributes composer.lock Daily Downloads

Stargazers

πŸ‘ Thank you very much stargazers ⭐ !!

You have proved that BK Sanitizers has some value !!

Stargazers repo roster for @PuneetGopinath/Sanitizers

Stargazers over time

Stargazers over time

About ℹ️

  • What is Sanitize ??

/ˈsanΙͺtʌΙͺz/ - to make something completely clean and free from bacteria.

In web development to sanitize means that you remove unsafe characters from the input.
Sanitize is a function to check (and remove) harmful data (which can harm the software) from user input.
Sanitizing user input is the most secure method of user input validation to strip out anything that is not on the whitelist.

  • When and why should I use Sanitizers ?

Whenever you store user's data (in database or anywhere), or if that data will be read/available to (unsuspecting) users, then you have to sanitize it.
See also HTML_sanitization in wikipedia

  • What is SQL injection ??

SQL injection is a method used by hackers to inject malicious SQL codes while running SQL query.

  • How can I clean user input 🧹 ?

  • First, Sanitize
  • Then, Validate
  • Last, Escape output. Validating process image

Visuals πŸ“½οΈ

  • Testing with and without composer autoload in Termux (on Android)

Gif of testing on termux

I ran:

composer validate # Validates composer.json
composer test # Test without composer autoload
composer update # Update dependencies and install autoload
composer test # Test with composer autoload

Files πŸ—ƒοΈ

Sanitizers/
└── src/
    β”œβ”€β”€ Sanitizers.php
    └── config.ini
    └── bootstrap.php
└── examples/
    └── README.md
    └── confirm-reg.php
    └── contact-form.php
    └── login.php
    └── register.php
└── test/
    └── SanitizersTest.php
    └── README.md

Prerequisites πŸ“‹

  • PHP

Minimum we need php 5.6.0 for Sanitizers to work.

  • PHP Extensions

You need filter and mbstring extension.

Tests βš™οΈ

Run either composer run-script test or php test/SanitizersTest.php debug

Contributing

Plz read CONTRIBUTING.md file.

Community πŸ’¬

Get updates on Sanitizers's development and chat with the BKS maintainers and community members.

  • Chat in IRC. On the irc.freenode.net server, in the #bksanitizers channel.
  • Also you can chat in gitter
  • Follow our blog on hashnode.dev
  • We might send messages (as comments) in this discussion, you can read those when you are free !!

Authors βœ’οΈ

See also the list of contributors who participated in building this project.

LICENSE πŸ“„

MIT License. Read LICENSE file. FOSSA Status

Comparing πŸ˜•

Are you comparing BKS library with HTMLPurifier ??

Then, you need to know difference between HTMLPurifier and BKS

  1. HTMLPurifier aims at creating safe and valid HTML as close as possible to a given input. But we aim to cover all types of input like name, username, password, etc

Sponsor

Support BK Sanitizers by becoming a sponsor. Your logo will be displayed here.

Just click the "Sponsor" button on our GitHub repo.

Become a sponsor

Spread BK Sanitizers! πŸŽ‰

Help spread awareness about BK Sanitizers by:

This is optional and you can also try to atleast give a star.

  • Share in social media platforms.
  • Add BK Sanitizers in your site's credits list OR add Powered by <a href="https://github.com/PuneetGopinath/Sanitizers/">BK Sanitizers</a>.
  • Give a star in GitHub

CODE_OF_CONDUCT

Plz read CODE_OF_CONDUCT.md for our CODE OF CONDUCT.

Conclusion 🏁

If you sanitize user input then, you will be able to manage data properly, validate it, show it in a secure and reliable way.

It makes your web application trustworthy, so it must be one of your main goals from the beginning of your career as a web developer.