Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit 8295cfd

Browse files
authored
fix: ipPinning - corretly import argon2, use #imports instead of #app for importing (#31)
1 parent afa1d66 commit 8295cfd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/runtime/server/middleware/session/ipPinning.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { argon2id, hash, verify } from 'argon2'
1+
import * as argon2 from 'argon2'
22
import { H3Event } from 'h3'
3-
import { useRuntimeConfig } from '#app'
43
import { Session } from '../../../../types'
54
import { IpMissingFromSession, IpMismatch } from './exceptions'
5+
import { useRuntimeConfig } from '#imports'
66

77
const argon2Options = {
88
// cryptographically-secure salt is generated automatically
9-
type: argon2id, // resistant against GPU & tradeoff attacks
9+
type: argon2.argon2id, // resistant against GPU & tradeoff attacks
1010
hashLength: 60
1111
}
1212

@@ -17,14 +17,14 @@ const argon2Options = {
1717
export const hashIpAddress = (ip: string | undefined): Promise<string | undefined> =>
1818
!ip
1919
? Promise.resolve(undefined)
20-
: hash(ip, argon2Options)
20+
: argon2.hash(ip, argon2Options)
2121

2222
/**
2323
* Check that the given (raw) IP address and the hashed IP address match
2424
* @param ip string|undefined The IP address to verify
2525
* @param ipHash string|undefined The (hashed) IP address to test against
2626
*/
27-
export const ipAddressesMatch = (ip: string | undefined, ipHash: string | undefined): Promise<boolean> => (!ip && !ipHash) ? Promise.resolve(false) : verify(ipHash, ip, argon2Options)
27+
export const ipAddressesMatch = (ip: string | undefined, ipHash: string | undefined): Promise<boolean> => (!ip && !ipHash) ? Promise.resolve(false) : argon2.verify(ipHash, ip, argon2Options)
2828

2929
/**
3030
* Extract the IP address from an HTTP header
@@ -58,7 +58,7 @@ export const getRequestIpAddress = ({ req }: H3Event): string | undefined => {
5858
return req.socket.remoteAddress
5959
}
6060

61-
export const getHashedIpAddress = (event: H3Event): Promise<string|undefined> => {
61+
export const getHashedIpAddress = (event: H3Event): Promise<string | undefined> => {
6262
return hashIpAddress(getRequestIpAddress(event))
6363
}
6464

0 commit comments

Comments
 (0)