Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
express-temp-links
Advanced tools
express-temp-links is an express module to use temporary routes easily
READ THIS BEFORE USE: since this module stores links in memory the links will become inaccessible after a server restart but you can use import
and export
methods to save links in a database using JSON format
npm i express-temp-links
const express = require( 'express' );
const TempLinks = require( 'express-temp-links' );
const app = express();
// This is an example middleware that checks if the client ip that requested a templink is the same that generated it
const myMiddleware = ( req, res ) => {
// req.templinks will be defined in temporary link routes
if ( req.ip === req.templink.refs ) {
res.send( 'This is a temporary link' );
} else {
res.send( 'You are not authorized' );
}
};
// This instanciates a new set of links that will expire in 10 seconds and call 'myMiddleware' function if a temporary link is requested
const tmpLinks = new TempLinks( { timeOut: 10, callback: myMiddleware } );
// This adds the instance to the selected path (in this example: '/'). You can change parameter name when you instanciate a new links set using 'paramName' option.
app.use( '/:templink', tmpLinks.parser() );
app.get( '/link-generate', ( req, res ) => {
// This generate a new temporary link with 'GET' method, sets client ip as refs parameter and return the new link string
const link = tmpLinks.get( { refs: req.ip } );
// This sends link to the client
res.send( `<a href="http://localhost:3000/${link}">http://localhost:3000/${link}</a>` );
} );
app.listen( 3000 );
TempLinks.constructor
const tmpLinks = new TempLinks( options: Object );
timeOut
- Link expiration in seconds (Default: 300)inteval
- Link expiration checking in milliseconds (Default: 1000)oneTime
- It sets if links will be deleted once accessed (Default: true)method
- It sets the default HTTP method (Default: undefined)refs
- It sets any data that can be accessed from req.templink.refsredirect
- Default string that will be passed to res.redirect if it's settedcallback
- Default middleware callback that will be launched when links are accessed if it's settedparamName
- The parameter name in express query routing (Default: 'templink')A new TempLinks
instance that extends EventEmitter
class, emits an added
event when a link is created and passes that
TempLinks.add
tmpLinks.add( options: Object );
timeOut
- Link timeout in secondsoneTime
- Delete link once is accessedmethod
- Any HTTP method you want to userefs
- Any refs you want to add to req when the link is accessedredirect
- A string that will be passed to res.redirect method when the link is accessed if it's settedcallback
- A middleware callback you want to launch when the link is accessed if it's settedA new temporary link as a string
TempLinks.get
tmpLinks.get( options: Object );
The same of add
method, except for method
A new temporary link as a string
TempLinks.post
tmpLinks.post( options: Object );
The same of add
method, except for method
A new temporary link as a string
TempLinks.export
tmpLinks.export()
The active links as a JSONable Object
TempLinks.import
tmpLinks.import( links: Object [, callback: Function] );
links
Required - A set of links that was exported previouslycallback
Optional - A middleware callback you want to associate to imported linksconst express = require( 'express' );
const TempLinks = require( 'express-temp-links' );
const app = express();
// This is an example middleware that checks if the client ip that requested a templink is the same that generated it
const tmpMiddleware = ( req, res ) => {
// req.templinks will be defined in temporary link routes
if ( req.ip === req.templink.refs ) {
res.send( 'This is a temporary link' );
} else {
res.send( 'You are not authorized' );
}
};
// This is another example middleware for another links set
const imgMiddleware = ( req, res, next ) => {
// It deletes non-oneTime links
req.templink.delete();
// Any action
// It launches next middleware function in the same route of the parser
next();
};
// This instanciates a new set of links that will expire in 10 seconds and it will call 'tmpMiddleware' function if a temporary link is requested
const tmpLinks = new TempLinks( { timeOut: 10, callback: tmpMiddleware } );
// This instanciates a new set of links that will expire in 5 minutes (by default), it will call 'imgMiddleware' function and links can be accessed many times
const imageLinks = new TempLinks( { oneTime: false, callback: imgMiddleware } );
// This logs any generated links by 'tmpLinks' instance
tmpLinks.on( 'added', ( lnk, obj ) => {
console.log( lnk );
console.log( obj.export() );
} );
tmpLinks.on( 'deleted', ( lnk, obj ) => {
// Other actions...
} );
// These add the instances to the selected paths (in this example: '/' and '/image/'). You can change parameter name when you instanciate a new links set using 'paramName' option.
app.use( '/:templink', tmpLinks.parser() );
app.use( '/image/:templink', imageLinks.parser(), ( req, res, next ) => {
if ( req.templink ) {
// If this req is an active templink...
// It sends 'Hello world'
res.send( req.templink.refs.join(' ') );
} else {
next();
}
} )
app.get( '/link-generate', ( req, res ) => {
// This generate a new temporary link, sets client ip as refs parameter and return the new link string
const link = tmpLinks.get( { refs: req.ip } );
// This generate a new temporary link, sets a refs parameter and return the new link string
const imgLink = imageLinks.get( { refs: ['Hello', 'world'] } );
// These send links to the client
res.send( `<a href="http://localhost:3000/${link}">http://localhost:3000/${link}</a>` );
res.send( `<a href="http://localhost:3000/${imgLink}">http://localhost:3000/${imgLink}</a>` );
} );
app.listen( 3000 );
FAQs
An express module to use temporary routes easily
The npm package express-temp-links receives a total of 1 weekly downloads. As such, express-temp-links popularity was classified as not popular.
We found that express-temp-links demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.