Skip to content

Commit ae291ce

Browse files
author
http://j3h.us/
committed
[project @ Only allow the example server to return positive assertions for the URL that it controls]
1 parent b518eed commit ae291ce

2 files changed

Lines changed: 26 additions & 35 deletions

File tree

‎examples/djopenid/server/views.py‎

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ def handleCheckIDRequest(request, openid_request):
141141
what Simple Registration information, if any, to send in the
142142
response.
143143
"""
144+
# If the request was an IDP-driven identifier selection request
145+
# (i.e., the IDP URL was entered at the RP), then return the
146+
# default identity URL for this server. In a full-featured
147+
# provider, there could be interaction with the user to determine
148+
# what URL should be sent.
149+
if not openid_request.idSelect():
150+
151+
id_url = getViewURL(request, idPage)
152+
153+
# Confirm that this server can actually vouch for that
154+
# identifier
155+
if id_url != openid_request.identity:
156+
# Return an error response
157+
error_response = ProtocolError(
158+
openid_request.message,
159+
"This server cannot verify the URL %r" %
160+
(openid_request.identity,))
161+
162+
return displayResponse(request, error_response)
163+
144164
if openid_request.immediate:
145165
# Always respond with 'cancel' to immediate mode requests
146166
# because we don't track information about a logged-in user.
@@ -161,10 +181,7 @@ def showDecidePage(request, openid_request):
161181
162182
@type openid_request: openid.server.server.CheckIDRequest
163183
"""
164-
idSelect = openid_request.idSelect()
165-
identity = openid_request.identity
166184
trust_root = openid_request.trust_root
167-
default_url = getViewURL(request, idPage)
168185
return_to = openid_request.return_to
169186

170187
try:
@@ -177,10 +194,7 @@ def showDecidePage(request, openid_request):
177194
return direct_to_template(
178195
request,
179196
'server/trust.html',
180-
{'idSelect': idSelect,
181-
'identity': identity,
182-
'trust_root': trust_root,
183-
'default_url': default_url,
197+
{'trust_root': trust_root,
184198
'trust_handler_url':getViewURL(request, processTrustResult),
185199
'trust_root_valid': trust_root_valid,
186200
})
@@ -194,31 +208,19 @@ def processTrustResult(request):
194208
# appropriate response.
195209
openid_request = getRequest(request)
196210

197-
result = None
198-
response_identity = openid_request.identity
211+
# The identifier that this server can vouch for
212+
response_identity = getViewURL(request, idPage)
199213

200214
# If the decision was to allow the verification, respond
201215
# accordingly.
202-
if 'allow' in request.POST:
203-
result = True
204-
elif 'cancel' in request.POST:
205-
# Otherwise, respond with False.
206-
result = False
207-
208-
# If the request was an IDP-driven identifier selection request
209-
# (i.e., the IDP URL was entered at the RP), look at the form to
210-
# find out what identity URL the user wanted to send.
211-
if openid_request.idSelect():
212-
response_identity = getViewURL(
213-
request,
214-
idPage, kwargs={'name':request.POST['name']})
216+
allowed = 'allow' in request.POST
215217

216218
# Generate a response with the appropriate answer.
217-
openid_response = openid_request.answer(result,
219+
openid_response = openid_request.answer(allowed,
218220
identity=response_identity)
219221

220222
# Send Simple Registration data in the response, if appropriate.
221-
if result:
223+
if allowed:
222224
sreg_data = {
223225
'fullname': 'Example User',
224226
'nickname': 'example',

‎examples/djopenid/templates/server/trust.html‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,7 @@
3131
<div>
3232
<form method="post"
3333
action="{{ trust_handler_url }}">
34-
{% if idSelect %}
35-
<p>
36-
Because you entered the server URL when authenticating, enter a
37-
username here to return an identity URL of your choice:
38-
39-
<br/>
40-
<input type="text" name="name" size="30" />
41-
(If you omit this, <tt>{{ default_url }}</tt> will be sent instead.)
42-
</p>
43-
{% else %}
4434
Verify your identity to the relying party?
45-
{% endif %}
4635

4736
<br/>
4837
<input type="submit" value="Yes (Allow)" name="allow" />

0 commit comments

Comments
 (0)