
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
nextjs-api-common-middleware
Advanced tools
A collection of commonly used Next.js API middleware patterns
This package exports some common Next.js API middleware patterns that you might need across different applications. It aims to provide useful and mostly flexible drop-in functions.
If you have something in mind that is generally help- or useful and is not included in this list, please feel free to open an issue.
yarn add nextjs-api-common-middleware
npm install --save nextjs-api-common-middleware
While generally not required, it is recommended that you re-export the middleware collection with your own default configuration.
Create a file called middleware.js/middleware.ts somewhere that suits you well, the contents of the file should look something like this:
import { createExport } from 'nextjs-api-common-middleware';
const m = createExport({
catch: (_req, res, err) => {
console.error(err);
res.status(500).send('An unknown error occurred');
},
auth: {
strategy: 'custom',
custom: (authHeaderValue, _req) => {
if (authHeaderValue && authHeaderValue === 'test') {
return {
uid: 123,
user: {
firstname: 'Test',
lastname: 'User',
},
};
}
return null;
},
},
});
export default m;
// src/pages/api/hello.js
import m from '../../middleware'; // or 'nextjs-api-common-middleware'
async function handler(req, res) {
res.json({ hello: 'world' });
}
export default m.auth(handler); // second argument could be additional options
// src/pages/api/hello.js
import m from '../../middleware'; // or 'nextjs-api-common-middleware'
async function handler(req, res) {
res.json({ hello: 'world' });
}
export default m._.chain([m.auth, m.guard], handler, {
// auth options are still remembered from the initial configuration
guard: {
required: ['foo'],
},
});
FAQs
A collection of commonly used Next.js API middleware patterns
We found that nextjs-api-common-middleware 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
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.