Skip to content
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

Relax regex parsing of csrf_token #142

Merged
merged 1 commit into from
Mar 5, 2025

Conversation

Techcable
Copy link
Contributor

The previous regex no longer works because instagram changed schema.

The relevant JSON now looks something like this:

["InstagramSecurityConfig",[],{"csrf_token":"abcdefg"},1234]

Obviously I changed the token and integer value.

No longer works because instagram changed schema.

The relevant JSON now looks something like this:
["InstagramSecurityConfig",[],{"csrf_token":"abcdefg"},1234]
self._session.headers.update({'x-csrftoken': m.group(1)})
m = list(re.finditer(r'{"csrf_token":"([^"]+)"', r.text))
assert len(m) == 1, m
self._session.headers.update({'x-csrftoken': m[0].group(1)})
Copy link
Owner

Choose a reason for hiding this comment

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

This assert was only there for typing purposes so you can remove the assert line and then wrap this line in try: ... except IndexError: raise CSRFTokenNotFound (create the exception similar to the ones at the top of client.py).

Also, please do me a favour and fix the quotes on line 228. I know it's not your fault they are there but it's a simple fix so this passes QA.

@Tatsh Tatsh self-assigned this Apr 14, 2024
@Tatsh Tatsh merged commit 5ab1834 into Tatsh:master Mar 5, 2025
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants