I'm creating an api for internal usage. I would like to restrict access to this api which has the prefix Xapi/v1/. Is there a simple and safer way to achieve this like using a middleware? e.g I just need 10.11.3.* IPs to be able to access this.
@bobbybouwmann Thanks. I'm going to try this. However, one thing I noticed (as we use CloudFlare) $request->ip() and/or $request->ips() is not listing the HTTP_X_FORWARDED_FOR. But, $request->server() lists it. Shouldn't ips() be including this as well?
Update:
It's definitely getting complicated with CloudFlare around (reverse proxy). To really configure nginx to identify CloudFlare IPs, there is no real dynamic way except manually updating their ip list.
So, here is what I'm trying
Ensure requests are coming to domain i.e via server_name (that indicates it's routed via CloudFlare)
Then look for X-Forwarded-For header
@bobbybouwmann as far as Laravel ($request->ips()) not showing the CloudFlare IP, it seems it'll only fetch trusted proxies. Symfony has a way to configure this within Front-Controller and not sure how this can be done in Laravel. So, research continues. Any insights into this will be great.