Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cookie-secure

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cookie-secure

This module for setting and getting secure cookies from

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
Maintainers
1
Weekly downloads
 
Created
Source

verson License

This node module for setting cookies securarly

This module sets and get cookie

  1. choose expires or max-age

  2. httponly set true to prevent access from client javascript access

  3. Same-site sting by defualt is strict other option is lax

  4. secure cookie is only allowed with https

First create cookistring

var cookieString =setCookieString(req, res, name, value, expires ,maxAge, httponly=true,https=false, SameSite="Strict");

call setcookie method

setCookie(req, res, cookieString, data="", resEnd=true);

var cuCokkie = getCookie(req, res, curCookie);

Below is example for tesing on localhost

Below code you will see how set https server as how to use secure cookie.

To get self signed SSL use on loacal host testing pupose use below command

/*
open git bash and type below commond to generate self signed ssl key and certifiacte
openssl genrsa 1024 > key.pem
openssl req -x509 -new -key key.pem > cert.pem
*/


var cookie = require("cookie-secure");

var https = require("https");

var fs = require("fs"); const options={ key : fs.readFileSync(__dirname + "/key.pem"), cert : fs.readFileSync(__dirname + "/cert.pem") }

https.createServer(options, (req, res) => { var curCookie = "testHTTPS"; if(req.url = "/"){ var co =cookie.setCookieString(req, res, curCookie ,"rve", "",606024,false,true); cookie.setCookie(req, res, co, "done",true); }else if(req.url == "/get_cookie"){ cookie.getCookie(req, res, curCookie); }

}).listen(8000);

var http = require("http"); http.createServer(function(req, res){ var curCookie = "testHTTP"; if(req.url = "/"){ var co = cookie.setCookieString(req, res, curCookie,"uemsh", Date(),606024,false, false); cookie.setCookie(req, res, co, "done",true);

}else if(req.url == "/get_cookie"){
    cookie.getCookie(req, res, curCookie);
}

}).listen(9000)

Keywords

FAQs

Package last updated on 24 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc