Code Monkey home page Code Monkey logo

django-admin-ip-restrictor's People

Contributors

richtier avatar sdonk avatar sgaist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-admin-ip-restrictor's Issues

getting rejections on requests that are not restricted

I believe we're seeing a bug related to the current open pull-request whereby requests to non-restricted IPs are throwing exceptions because they're private IPs. In the example below, our config is setup to just restrict access to ["admin"] yet, we're seeing exceptions related to the middleware

"GET /api/config HTTP/1.0" 500 27<socket.socket fd=6, family=AddressFamily.AF_INET, 
type=SocketKind.SOCK_STREAM, proto=0, laddr=('172.17.0.2', 8000), raddr=('172.17.0.3', 46444)>Traceback (most recent call last):
  File "/root/.local/share/virtualenvs/portal-lhpYkIEg/lib/python3.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/root/.local/share/virtualenvs/portal-lhpYkIEg/lib/python3.7/site-packages/django/core/handlers/base.py", line 178, in _get_response
    response = middleware_method(request, callback, callback_args, callback_kwargs)
  File "/root/.local/share/virtualenvs/portal-lhpYkIEg/lib/python3.7/site-packages/admin_ip_restrictor/middleware.py", line 81, in process_view
    ip = self.get_ip(request)
  File "/root/.local/share/virtualenvs/portal-lhpYkIEg/lib/python3.7/site-packages/admin_ip_restrictor/middleware.py", line 76, in get_ip
    assert is_routable, 'IP is private'
AssertionError: IP is private 

Document examples using ip ranges

Blocking ips is fairly obvious, not so much with ip ranges.

It would be good to have a couple of example in the documentation showing this.

HTTP_X_FORWARDED_FOR can contain multiple IPs

HTTP_X_FORWARDED_FOR can contain a comma seperated list of IPs, and you only want to check one of them (which one may vary depending on if you use a CDN or not).

You can prepend your own IP using curl, e.g.

curl --header X-Forwarded-For '1.1.1.1,2.2.2.2,3.3.3.3 ..'

You get a resulting x-forwarded of: (edited)
1.1.1.1, 2.2.2.2, 3.3.3.3, {the client's real ip}, {cloudfront's ip}

So you need need a way of telling django-admin-restrictor the index of the IP you want from the end, I guess the sane default for this would be -1, but for the sites using cloudfront they will want -2.

Invest PIR has a solution to grab the second to last IP, which is hardcoded, along with unit tests in this PR
uktrade/invest-pir-api@5454251

I'm not sure how the setting would be spelt X_FORWARDED_INDEX ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.