
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@distributedlab/json-api-client
Advanced tools
JSON API client
// interceptors.ts
import { HTTPS_STATUS_CODES } from '@distributedlab/json-api-client'
import { AxiosInstance, AxiosRequestConfig } from 'axios'
import { useAuthStore } from '@/store'
import { router } from '@/router'
import { Bus } from '@/utils'
import { ROUTE_NAMES } from '@/enums'
import { useI18n } from '@/localization'
export function attachBearerInjector(axios: AxiosInstance): void {
axios.interceptors.request.use((request): AxiosRequestConfig => {
// Some authentication store in the client app
const authStore = useAuthStore()
if (!authStore.accessToken) return request
if (!request.headers) request.headers = {}
// Attach bearer token to every request
request.headers['Authorization'] = `Bearer ${authStore.accessToken}`
return request
})
}
export function attachStaleTokenHandler(axios: AxiosInstance): void {
axios.interceptors.response.use(
response => response,
async error => {
const config = error?.config
const isUnauthorized = (
error?.response?.status === HTTPS_STATUS_CODES.UNAUTHORIZED &&
!config?._retry
)
// If error isn't unauthorized or request was already retried - return error
if (!isUnauthorized) return Promise.reject(error)
// Some authentication store in the client app
const authStore = useAuthStore()
const { $t } = useI18n()
try {
config._retry = true
// Executes some refresh token logic in the client app
await authStore.refreshToken()
// Reset default axios authorization header witn new token
axios.defaults.headers.common['Authorization'] = `Bearer ${authStore.accessToken}`
return axios(config)
} catch (_error) {
/** Example of handling refresh token error in the client app
*
* Implementation may differ from example
*
* We can logout user and redirect him to the login page and
* emit bus error event to show user that session expired
*/
authStore.logout()
router.push({ name: ROUTE_NAMES.login })
Bus.error({
title: $t('api-errors.session-expired-title'),
message: $t('api-errors.session-expired-desc'),
})
return Promise.reject(_error)
}
},
)
}
// api.ts
import { JsonApiClient } from '@distributedlab/json-api-client';
import { attachBearerInjector, attachStaleTokenHandler } from '@/interceptors';
const axiosInstance = axios.create()
attachBearerInjector(axiosInstance)
attachStaleTokenHandler(axiosInstance)
export const api = new JsonApiClient({
baseUrl: 'https://api.example.com',
axios: axiosInstance,
});
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
1.0.0
FAQs
API Client for JSON API
The npm package @distributedlab/json-api-client receives a total of 1 weekly downloads. As such, @distributedlab/json-api-client popularity was classified as not popular.
We found that @distributedlab/json-api-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.