Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@types/method-override
Advanced tools
TypeScript definitions for method-override
@types/method-override provides TypeScript definitions for the method-override middleware, which allows you to use HTTP verbs such as PUT or DELETE in places where the client doesn't support it.
Override HTTP Methods
This feature allows you to override HTTP methods using a custom header. In this example, the middleware checks for the 'X-HTTP-Method-Override' header and uses its value to override the HTTP method.
const methodOverride = require('method-override');
const express = require('express');
const app = express();
// Override with the X-HTTP-Method-Override header in the request
app.use(methodOverride('X-HTTP-Method-Override'));
app.post('/resource', (req, res) => {
res.send('POST request to the resource');
});
app.put('/resource', (req, res) => {
res.send('PUT request to the resource');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
Override using a query value
This feature allows you to override HTTP methods using a query parameter. In this example, the middleware checks for the '_method' query parameter and uses its value to override the HTTP method.
const methodOverride = require('method-override');
const express = require('express');
const app = express();
// Override with the _method query parameter in the request
app.use(methodOverride('_method'));
app.post('/resource', (req, res) => {
res.send('POST request to the resource');
});
app.put('/resource', (req, res) => {
res.send('PUT request to the resource');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
Connect is a middleware framework for Node.js, offering a collection of high-performance 'plugins' known as middleware. It can be used to create a custom method override middleware similar to method-override.
Body-parser is a middleware to handle the request body in Node.js. While it doesn't directly provide method overriding, it is often used in conjunction with method-override to parse incoming request bodies before method overriding.
Express is a web application framework for Node.js. It provides a robust set of features for web and mobile applications, including routing and middleware support. Method-override is often used as middleware in Express applications.
npm install --save @types/method-override
This package contains type definitions for method-override (https://github.com/expressjs/method-override).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/method-override.
declare namespace Express {
export interface Request {
originalMethod?: string | undefined;
}
}
import express = require("express");
declare namespace e {
export interface MethodOverrideOptions {
methods: string[];
}
}
declare function e(
getter?: string | ((req: express.Request, res: express.Response) => string),
options?: e.MethodOverrideOptions,
): express.RequestHandler;
export = e;
Last updated: Mon, 02 Dec 2024 21:33:37 GMT
Dependencies: none
Peer dependencies: @types/express
These definitions were written by Santi Albo.
FAQs
TypeScript definitions for method-override
The npm package @types/method-override receives a total of 290,947 weekly downloads. As such, @types/method-override popularity was classified as popular.
We found that @types/method-override demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.