Security and code quality improvements. #620
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello Flask-WTF Developers,
As a high school student currently involved with the Research School project, I am researching secure programming practices, code quality, and generally "good programming" in relation to security. I am currently done with the research part, and I am trying to apply my findings and research to open source projects, such as this one.
Why Flask-WTF? The Flask-WTF extension plays an important role in the Flask ecosystem. Specifically, in security issues and backend code tidiness. The students who have submitted their code to the project (their code isn't available in the repo due to licensing things) used Flask-WTF to improve their code, thus, thought why not contribute :D
I did a few improvements that I would like to propose:
isort
, code formatted withblack
.secrets.token_hex(20)
to streamline the code and reduce unnecessary computational overhead. If hashing is still preferred, I recommend usinghashlib.blake2b()
withdigest_size=20
, as it is faster and more secure than SHA1, especially on 64-bit platforms.file.tell()
for efficiency reasons. I also made sure it is returned to the original file pointer over resetting back to 0, which should ensure WTF works everywhere.recaptcha/widgets.py
.Before making this PR I have run the tests to ensure I haven't broken anything.
Thank you for reviewing my pull request. I look forward to hearing your feedback <3
Checklist:
docs/changes.rst
summarizing the change and linking to the issue. Add.. versionchanged::
entries in any relevant code docs.