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.
fusion-plugin-csrf-protection
Advanced tools
Generic CSRF-protection utility for use with any session manager or csrf secret/token generator
Provides a modified fetch
that is automatically secure against CSRF attacks for non-idempotent HTTP methods.
yarn add fusion-plugin-csrf-protection
import {createPlugin} from 'fusion-core';
import {FetchToken} from 'fusion-tokens';
const pluginUsingFetch = createPlugin({
deps: {
fetch: FetchToken,
},
provides: ({fetch}) => {
return {
getUser: () => {
return fetch('/get-user');
}
}
},
});
// src/main.js
import React from 'react';
import {FetchToken} from 'fusion-tokens';
import App from 'fusion-react';
import CsrfProtectionEnhancer, {
CsrfIgnoreRoutesToken,
} from 'fusion-plugin-csrf-protection';
import fetch from unfetch;
export default () => {
const app = new App(<div></div>);
app.register(FetchToken, fetch);
app.enhance(FetchToken, CsrfProtectionEnhancer);
// optional
__NODE__ && app.register(CsrfIgnoreRoutesToken, []);
}
Assuming this plugin has already been registered, fetch
can be consumed from React via useService
(React v16.8+ required):
import {useService} from 'fusion-react';
import {FetchToken} from 'fusion-tokens';
function Component() {
const fetch = useService(FetchToken);
// ...
}
See useService
docs in fusion-react
for more information.
CsrfProtectionEnhancer
import CsrfProtectionEnhancer from 'fusion-plugin-csrf-protection';
The CSRF protection enhancer. Typically, it should be used to enhance the FetchToken
.
This enhances the FetchToken
and provides the fetch api and a server side middleware for validating CSRF requests.
FetchToken
import {FetchToken} from 'fusion-tokens';
The canonical token for an implementation of fetch
. This CSRF plugin is generally registered as an enhancer on that token.
For more, see the fusion-tokens repo.
CsrfIgnoreRoutesToken
import {CsrfIgnoreRoutesToken} from 'fusion-plugin-csrf-protection';
A list of routes to ignore csrf protection on. This is rarely needed and should be used with caution.
Types
type CsrfIgnoreRoutes = Array<string>;
Default value
Empty array []
const response: Response = fetch('/test', {
method: 'POST',
})
fetch: (url: string, options: Object) => Promise
- Client-only. A decorated fetch
function that automatically does pre-flight requests for CSRF tokens if required.
See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API for more on the fetch api.
FAQs
Generic CSRF-protection utility for use with any session manager or csrf secret/token generator
The npm package fusion-plugin-csrf-protection receives a total of 11 weekly downloads. As such, fusion-plugin-csrf-protection popularity was classified as not popular.
We found that fusion-plugin-csrf-protection 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.