Skip to content

gh-90309: Base64-encode cookie values embedded in JS#148848

Open
sethmlarson wants to merge 1 commit intopython:mainfrom
sethmlarson:morsel-js-output
Open

gh-90309: Base64-encode cookie values embedded in JS#148848
sethmlarson wants to merge 1 commit intopython:mainfrom
sethmlarson:morsel-js-output

Conversation

@sethmlarson
Copy link
Copy Markdown
Contributor

@sethmlarson sethmlarson commented Apr 21, 2026

Avoids problems arising from embedding arbitrary characters in JavaScript in .js_output() method. I'll be submitting a follow-up issue and PR to deprecate the function as suggested in #90309 cc @komi22

Comment thread Lib/http/cookies.py
return '<%s: %s>' % (self.__class__.__name__, self.OutputString())

def js_output(self, attrs=None):
import base64
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use lazy on the main branch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StanFromIreland Is there a substantial performance difference for using lazy if the module is used immediately after it's imported? I am new to the lazy keyword! :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that @StanFromIreland meant that we can use lazy import at module level.

But this will make backporting more difficult.

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I am not expert in JavaScript.

How old is the atob() function? Can we be sure that it is supported absolutely everywhere, not only in Firefox/Chromium clones?

Comment thread Lib/http/cookies.py
return '<%s: %s>' % (self.__class__.__name__, self.OutputString())

def js_output(self, attrs=None):
import base64
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that @StanFromIreland meant that we can use lazy import at module level.

But this will make backporting more difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants