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

✨ Optionally validate DigiD mock IDP callback urls #86

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

swrichards
Copy link
Contributor

Closes #85

@swrichards swrichards force-pushed the 85-validate-mock-idp-callbacks branch from be766a1 to 7abfb4e Compare January 6, 2025 16:44
Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.50%. Comparing base (7cec7f3) to head (484e3e9).
Report is 12 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #86      +/-   ##
==========================================
+ Coverage   92.31%   92.50%   +0.19%     
==========================================
  Files          48       48              
  Lines        1691     1734      +43     
  Branches      107      116       +9     
==========================================
+ Hits         1561     1604      +43     
  Misses         96       96              
  Partials       34       34              
Flag Coverage Δ
base 91.33% <100.00%> (+0.25%) ⬆️
oidc 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@swrichards swrichards force-pushed the 85-validate-mock-idp-callbacks branch 3 times, most recently from 2194959 to 97b9b9e Compare January 7, 2025 08:26
@swrichards swrichards marked this pull request as ready for review January 7, 2025 08:31
@swrichards swrichards force-pushed the 85-validate-mock-idp-callbacks branch 2 times, most recently from d7e593b to b16210d Compare January 7, 2025 08:37
Comment on lines 25 to 28
def is_relative_path(uri: str) -> bool:
"""Check if `uri` is a relative path."""
parsed = urlparse(uri)
return not (parsed.scheme or parsed.netloc)
Copy link
Member

Choose a reason for hiding this comment

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

here be dragons - please check the comments in the django source code for _url_has_allowed_host_and_scheme!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair, there's some gnarly edge cases to consider, clearly. In light of that, I think life's too short (in the context of this story) to care much about the relative callbacks. Delegating this fully to the Django library, which means callbacks will have to be fully qualified if the flag is set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sergei-maertens I fully delegated the safety checks to the existing utility helper, with the caveat that non-https callbacks are allowed if the mock IDP is currently hosted under regular HTTP. Related to this, the default setting for the flag is taken from settings.DEBUG, on the assumption that the callback validation is not required for (local) dev, and if somebody is using the IDP in a world-facing environment, the validation should be enabled (and thus follow the DEBUG setting, further assuming that best practices wrt disabling DEBUG are followed).

Copy link
Member

Choose a reason for hiding this comment

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

f the mock IDP is currently hosted under regular HTTP

hosting anything not under HTTPS and throwing pentests at it is an exercise in futility anyway, so acknowledged but dismissed :-)

digid_eherkenning/views/base.py Outdated Show resolved Hide resolved
digid_eherkenning/mock/idp/views/digid.py Outdated Show resolved Hide resolved
@swrichards swrichards force-pushed the 85-validate-mock-idp-callbacks branch from 9c58811 to 484e3e9 Compare January 8, 2025 11:27
@sergei-maertens sergei-maertens merged commit f3d0238 into master Jan 8, 2025
17 checks passed
@sergei-maertens sergei-maertens deleted the 85-validate-mock-idp-callbacks branch January 8, 2025 11:42
"""
Whether to validate that the `next_url` and `cancel_urls` are safe
"""
flag = getattr(settings, "DIGID_MOCK_IDP_VALIDATE_CALLBACK_URLS", settings.DEBUG)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sergei-maertens I clearly had a brain fade here, this should have been not settings.DEBUG 🤦‍♂️ I'll fix that up separately for a future patch release, don't think this warrants any other drastic action.

Copy link
Member

Choose a reason for hiding this comment

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

Feel to just patch it on master and bump the version + tag it, then we don't forget about it.

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.

Mock IDP view does not validate redirect urls
2 participants