Skip to content

Commit

Permalink
adding env var
Browse files Browse the repository at this point in the history
  • Loading branch information
mat1asm committed Apr 3, 2024
1 parent 5bf5ff6 commit 9b962d8
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions backend/src/handlers/authorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,29 @@ import {
} from 'aws-lambda'
import geoIP from 'fast-geoip'

const DEFAULT_DENY_LIST = ['CU', 'IR', 'IQ', 'KP', 'RU', 'SY', 'GB', 'US', 'UA']

export const authorizer = async (
authorizerEvent: APIGatewayRequestAuthorizerEventV2
): Promise<
APIGatewaySimpleAuthorizerWithContextResult<Record<string, string>>
> => {
let denyList = process.env.DENY_LIST?.split(',') ?? DEFAULT_DENY_LIST

Check failure on line 14 in backend/src/handlers/authorizer.ts

View workflow job for this annotation

GitHub Actions / test

'denyList' is never reassigned. Use 'const' instead
let authorized = true
let country
const ip = authorizerEvent.requestContext.http.sourceIp

try {
const ip = authorizerEvent.requestContext.http.sourceIp
console.log('IP:', ip)
const geo = await geoIP.lookup(ip)
country = geo?.country ?? 'unknown'
if (
['CU', 'IR', 'IQ', 'KP', 'RU', 'SY', 'GB', 'US', 'UA', 'AR'].includes(
country
)
) {
if (denyList.includes(country)) {
authorized = false
}
} catch (err) {
console.error('Error looking up country', err)
}

console.log('Country:', country)
console.log('Authorized:', authorized)
console.log(`IP:${ip} - Country:${country} - Authorized:${authorized}`)

return {
isAuthorized: authorized,
Expand Down

0 comments on commit 9b962d8

Please sign in to comment.