🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@trendyol-js/safe-redirect

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trendyol-js/safe-redirect

Resolves open-redirection issue

npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

safe-redirect

safe-redirect is a library which resolves open-redirection vulnerability when we need to make client-side redirection to a path taken from query string.

Example

For example, we have /login page and after successful login we need to redirect user to a path. Referrer can state the redirection path using callback query string parameter. Url looks like:

https://domain.com/login?callback=/payment

In /login page, after successful login, we implement the aforementioned requirement in this way:

// successful login
const path = new URLSearchParams(window.location.search).get("callback");
window.location.assign(path);

And here we have a open-redirection vulnerability

Case 1

https://fake.com can redirect user to domain.com/login?callback=https://fake.com/fake , after successful login, the user will be redirected to https://fake.com/fake.

Case 2

A site can redirect user to domain.com/login?callback=javascript:alert(document.cookie) and execute custom javascript code. (sensitive user data can be stolen, etc).

Solution

safe-redirect library solves this vulnerability. Simply:

npm i @trendyol-js/safe-redirect

import { redirect } from "@trendyol-js/safe-redirect";

// successful login
redirect("callback"); // give name of the query parameter
Feel free to contribute

Keywords

open-redirection

FAQs

Package last updated on 04 Aug 2020

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