Reputation: 277
I have seen two ways of redirecting after submitting a form. Inspecting the next
parameter:
return redirect(request.args.get('next', '/'))
Or using the referrer
:
return redirect(request.referrer)
How does each one work and what is the difference between the two?
Upvotes: 0
Views: 76
Reputation: 127240
The first relies on you setting a next
value in the query string, and will redirect to that url if supplied (or the default if not). The second would redirect to the page the browser got to the current page from.
Neither can be trusted as-is because both can be changed by the user. If you only want to redirect to pages within your own application, you'll need to validate that the target is either a relative URL or the domain name, port, and scheme are the same.
Upvotes: 1