Skip to content

onedionys/onedionys-csrf-protection-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to One Dionys - CSRF Protection Middleware! 👋

Middleware to protect applications from CSRF (Cross-Site Request Forgery) attacks by adding tokens to HTTP requests. 💖

💾 Requirements

  • Web Browser - Can be used as an emulator to build applications. Example [Chrome, Firefox, Safari & Opera].
  • Internet - Because many use CDN and to make it easier to find solutions to all problems.

🎯 How To Use

Example Syntax

const express = require('express');
const session = require('express-session');
const csrfMiddleware = require('./src/csrfMiddleware');

const app = express();

// Setup session middleware
app.use(session({
    secret: 'your_secret_key',
    resave: false,
    saveUninitialized: true
}));

// Use CSRF protection middleware
app.use(csrfMiddleware);

// Your other middleware and routes

app.listen(3000, () => {
    console.log('Server is running on port 3000');
});

Explanation

  • This middleware generates a CSRF token and stores it in the user's session. It adds this token to requests as a hidden field in forms or as a custom HTTP header. When the user submits a form or makes a request, the server verifies that the CSRF token matches the one stored in the session, protecting against CSRF attacks.

Return Value

  • The middleware returns a function that acts as middleware in Express.js applications. This function adds CSRF protection to routes by generating and storing CSRF tokens in user sessions.

📆 Release Date

  • v1.0.0 : 17 March 2024
  • v1.0.1 : 18 March 2024
  • v5.0.0 : 31 March 2024

🧑 Author

📝 License

  • Copyright © 2024 One Dionys
  • One Dionys - CSRF Protection Middleware is an open source project licensed under the MIT license

☕️ Suppport & Donation

Love One Dionys - CSRF Protection Middleware? Support this project by donating or sharing with others in need.

Made with ❤️ One Dionys

About

Middleware to protect applications from CSRF (Cross-Site Request Forgery) attacks by adding tokens to HTTP requests.

Resources

License

Stars

Watchers

Forks

Packages

No packages published