-
-
Notifications
You must be signed in to change notification settings - Fork 931
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
generate boundary with token_hex #2702
Conversation
starlette/responses.py
Outdated
@@ -404,7 +404,7 @@ async def _handle_multiple_ranges( | |||
file_size: int, | |||
send_header_only: bool, | |||
) -> None: | |||
boundary = "".join(random_choices("abcdefghijklmnopqrstuvwxyz0123456789", k=13)) | |||
boundary = token_hex(20) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was it increased to 20?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just A random number I picked. len(boundary) is actually 40 now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the specification, this value can be between 1 and 70. But is 40 too long?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>96 bits of entropy is recommended so only 13 bytes is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trim21 Can we drop the number a bit so I can include this on the next release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to what? 13?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Maybe we can add a comment about the choice, to avoid future confusion/questions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
96 bits of entropy is recommended so only 13 bytes is needed
where does this recommendation comes from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whatwg/html#6424 (comment)
https://andreubotella.github.io/multipart-form-data/#serializing
https://github.com/andreubotella/multipart-form-data/blob/main/index.bs#L32
Also I misremembered the recommendation it's 95 bits, so 12 bytes would be sufficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elegant modification.
* generate boundary with token_hex * generate boundary with token_hex * fix * boundary size * Update starlette/responses.py --------- Co-authored-by: Marcelo Trylesinski <[email protected]>
Summary
Checklist