Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add geoip based request blocking #17

Merged
merged 3 commits into from
Jan 4, 2024

Conversation

techsavvyash
Copy link
Member

Description

This PR adds the functionality to block requests based on geoip locations, initially we only allow requests from India and block all other requests. The geolocation service used right now is the one we have deployed at https://geoip.samagra.io/.

Changes

A new interceptor has been implemented in the file src/interceptors/geoip.interceptor.ts and this interceptor has been registered in the main.ts file as a global interceptor. Further a new package named @nestjs/axios has been added in the service.

How to test

Try sending requests from various IP address via IP spoofing.

Please consider using the closing keyword if the pull request is proposed to
fix an issue already created in the repository
(https://help.github.com/articles/closing-issues-using-keywords/)

@Amruth-Vamshi Amruth-Vamshi merged commit 4dd6a02 into AgrI-Mitra:main Jan 4, 2024
3 checks passed
src/interceptors/geoip.interceptor.ts Show resolved Hide resolved

if (country !== 'India') {
this.logger.verbose('Denying request from ip: ' + clientIp + ' country: ' + country)
throw new HttpException('Access Denied', HttpStatus.FORBIDDEN);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we respond saying that this app can only be accessed in XYZ region as an output? It can either be a header or a JSON response.

src/interceptors/geoip.interceptor.ts Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants