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

Can't read cookies #79

Closed
tkell opened this issue Mar 18, 2017 · 6 comments
Closed

Can't read cookies #79

tkell opened this issue Mar 18, 2017 · 6 comments

Comments

@tkell
Copy link

tkell commented Mar 18, 2017

Hello!

I'm working on some stuff for SecureDrop, and it looks like maybe tbselenium can't read cookies, using driver.get_cookies().

I can set cookies using driver.add_cookies(), and read them back - but when I see a Cookie header in tcpdump, I can't read the cookie in question.

This could well be a problem with the test setup for SecureDrop - I don't have a minimal example, but I'll work on one.

Thanks!

@tkell
Copy link
Author

tkell commented Mar 18, 2017

Example using Twitter login:

from tbselenium.tbdriver import TorBrowserDriver

pref_dict = {'network.proxy.no_proxies_on': '.twitter.com'}
with TorBrowserDriver("/opt/tbb/tor-browser_en-US/", pref_dict=pref_dict) as driver:
    driver.implicitly_wait(5)

    driver.get('https://twitter.com/login')
    username_field = driver.find_element_by_css_selector('input[class="js-username-field email-input js-initial-focus"]')
    username_field.send_keys('<TWITTER_USERNAME>')
    password_field = driver.find_element_by_css_selector('input[class="js-password-field"]')
    password_field.send_keys('<TWITTER_PASSWORD>')

    submit_button = driver.find_element_by_css_selector('button[class="submit btn primary-btn"]')
    submit_button.click()

    print driver.current_url
    print driver.get_cookies()

This outputs:

https://twitter.com/
[]

@gunesacar
Copy link
Collaborator

Thanks for reporting.

I tried with vanilla FirefoxDriver and get the same result (no cookies).
Also, reading https://github.com/robotframework/Selenium2Library/issues/177, I'm thinking that this may be a FirefoxDriver issue.

If that's compatible with what you're doing, you can disable PBM to access cookies.
Just add "browser.privatebrowsing.autostart": False to the pref_dict you have.
(Idea from https://github.com/robotframework/Selenium2Library/issues/177#issuecomment-37808376)

Disabling PBM may have side effects like storing things on the disk, please make sure it's OK for your case.

You can also use driver.execute_script("return document.cookie"), but httponly cookies will be missing in the list.

@tkell
Copy link
Author

tkell commented Mar 19, 2017

That config fixes it, 10,000 thanks!

Feel free to close this issue – I'll circle back with SecureDrop people to see if that's an acceptable bit of config to have in the tests.

@gunesacar
Copy link
Collaborator

I'm glad it worked. Maybe I should add a note about this in the troubleshooting section.

Thanks again for reporting.

gunesacar added a commit that referenced this issue Mar 20, 2017
Mention the expected selenium version.
@kushaldas
Copy link

Note: "browser.privatebrowsing.autostart": False works when working against 127.0.0.1 address, but not with the onion addresses. Could not find an way to get the cookies.

@gunesacar
Copy link
Collaborator

I could print the cookies on http://www.propub3r6espa33w.onion/ using the following code: https://gist.github.com/gunesacar/0e0acfa8d71deffe6c45ccd29b8247f1

I run the following...:
python cookie_check.py /path/to/tor-browser_en-US/ https://www.propub3r6espa33w.onion/

...it prints (along with a ton of other debug messages from Firefox):

Finished loading https://www.propub3r6espa33w.onion/
Cookies: pp-tracking={"pageCount":0}; __gads=ID=5b2f86bbd40732dd:T=1517883426:S=ALNI_Mb57Tl8YkAq9jenlcBbufsbX9yLJQ```

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

No branches or pull requests

3 participants