Skip to content

Commit

Permalink
Enforce HerokuappAccess (#78)
Browse files Browse the repository at this point in the history
* remove BlueRacer support

* Enforce HerokuappAccess whitelisting even if list is unset/empty

Refs teamniteo/operations#2359
  • Loading branch information
zupo authored Nov 7, 2024
1 parent c7b2900 commit c0bd66c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
7 changes: 1 addition & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,4 @@ jobs:

- run:
name: Test
command: poetry run pytest --junitxml junit.xml --cov=pyramid_heroku --cov-fail-under=100

- run:
name: Upload results to blueracer.io
command: |
bash <(curl -s https://app.blueracer.io/upload)
command: poetry run pytest --cov=pyramid_heroku --cov-fail-under=100
8 changes: 3 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ pyramid_heroku is a collection of tweens and helpers to successfully run `Pyrami

It provides the following:

* ``ClientAddr`` tween that sets real user's IP to ``request.client_addr``
* ``ClientAddr`` tween that sets real user's IP to ``request.client_addr``. Without this tween you cannot do IP-based geolocation, IP whitelisting, etc.
* ``Host`` tween that sets `request.host` to proxied `X-Forwarded-Host` header (note: potential security risk)
* ``HerokuappAccess`` tween that denies access to your app's
``<app>.herokuapp.com`` domain for any non-whitelisted IPs.
* ``migrate.py`` script for automatically running alembic migrations on
deploy.
* ``HerokuappAccess`` tween that denies access to your app's ``<app>.herokuapp.com`` domain for any non-whitelisted IPs. This is helpful because you don't want anyone outside your team (i.e. usual visitors/users and search bots) to be able to visit ``<app>.heroku.com`` besides the domain the app is deployed on. This is for security and SEO purposes.
* ``migrate.py`` script for automatically running alembic migrations on deploy.
* ``maintenance.py`` script for controlling Heroku maintenance mode.


Expand Down
4 changes: 1 addition & 3 deletions pyramid_heroku/herokuapp_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ def __init__(self, handler, registry):

def __call__(self, request):
whitelisted_ips = request.registry.settings.get(
"pyramid_heroku.herokuapp_whitelist"
"pyramid_heroku.herokuapp_whitelist", []
)
if not whitelisted_ips:
return self.handler(request)

if (
"herokuapp.com" in request.headers["Host"]
Expand Down
6 changes: 4 additions & 2 deletions pyramid_heroku/tests/test_herokuapp_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,23 @@ def test_other_hostname(self):
self.handler.assert_called_with(self.request)

def test_herokuapp_whitelist_not_set(self):
"Even if whitelist is not set, the protection should still work."
from pyramid_heroku.herokuapp_access import HerokuappAccess

self.request.client_addr = "6.6.6.6"
self.request.headers = {"Host": "foo.herokuapp.com"}
self.request.registry.settings = {}

HerokuappAccess(self.handler, self.request.registry)(self.request)
self.handler.assert_called_with(self.request)
assert not self.handler.called, "handler should not be called"

def test_herokuapp_whitelist_empty(self):
"Even if whitelist is empty, the protection should still work."
from pyramid_heroku.herokuapp_access import HerokuappAccess

self.request.client_addr = "6.6.6.6"
self.request.headers = {"Host": "foo.herokuapp.com"}
self.request.registry.settings = {"pyramid_heroku.herokuapp_whitelist": []}

HerokuappAccess(self.handler, self.request.registry)(self.request)
self.handler.assert_called_with(self.request)
assert not self.handler.called, "handler should not be called"
1 change: 0 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[pytest]
addopts = --doctest-modules
junit_duration_report = call

0 comments on commit c0bd66c

Please sign in to comment.