Skip to content

WTForms 3 / deprecated SecureForm #216

@MM1nd

Description

@MM1nd

WTForms 3 will remove deprecated Extensions, namely SecureForm. This has already been done here: https://github.com/wtforms/wtforms so I guess things are getting serious.

tl:dr; I did something about that.

For what it's worth, I made a fork that does the following:

  • Do not longer inherit from SecureForm, but directly from Form
  • Make use of WTForms class Meta to configure CSRF
  • Remove functionality to generate/validate csrf tokens from both the form and the csrf module and let this be handled by the functionally equivalent SessionCSRF from WTForms to reduce redundancy. Also as to not have two subtly incompatible implementations in place.
  • Make changes to CsrfProtect as to use SessionCSRF in place of the old implementation. Currently it works by creating a Dummy Form on generation and vaildation of csrf tokens. There ought to be a better solution but that will probably require even more changes to CsrfProtect or new code redundancy.

[As an aside: In principle there is an alternative to this approach which is to provide an implementation of WTForms CSRF base class, that uses flask-wtf's csrf implementation. But since the implementations were functionally equivalent I saw no use in that. If you absolutely must keep the current CsrfProtect implementation unchanged, however, that's the way to go. Then again, my changes should make it easier to plug other implementations of WTForms CSRF into CsrfProtect, which in and of itself is a plus.]

(Maybe unfortunately) I also made some flavour changes:

  • Removed hidden_tag() which I personally found to be counter intuitive. IMO this should be solved on field level.
  • Included widget for HiddenInputs that retains most of hidden_tag's old functionality in the place where it belongs IMO.
  • Modified tests as to work without hidden_tag()
  • Modified tests as to work out of Visual Studio (yeah, sorry about that one)

I know the latter list will be controversial and contains breaking changes therefore I will make no pull request. However, feel free to head over to https://github.com/MM1nd/flask-wtf and use whatever you like.

Alex

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions