Support » Plugin: Login with Amazon » Improper use of sessions

  • Hello,

    We are facing multiple issues with this plugin:

    1) Plugin is creating sessions, even for guest users. This causes problems with caching mechanisms (such as varnish: it will MISS because there are cookies being set)
    2) Plugin is using PHP’s native session_* functions instead of WP’s core

    We are primarily having an issue with #1. How can we get around this but still allow logins?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author login-with-amazon

    (@login-with-amazon)

    Thanks, we’re looking into this.

    Hello @login-with-amazon,

    Do you have an update with this?

    deltafactory

    (@deltafactory)

    @login-with-amazon, I believe WP nonces will effectively replace the CSRF authenticator without use of sessions.
    https://codex.wordpress.org/WordPress_Nonces

    Even if it’s imperfect for your purposes, the routines for generating the nonce should give you a starting point for a deterministic, unique, repeatable value instead of a stored random value.

    I will be working on some LWA-based enhancements and may use this plugin as a starting point. If the developers are willing to accept patches, I’ll be happy to follow up.

    Plugin Author login-with-amazon

    (@login-with-amazon)

    Actually, if you read the WordPress nonces documentation, it clearly states: “Nonces should never be relied on for authentication or authorization, access control.” (emphasis mine)

    Transients were no good either, because while one can guarantee a maximum life, minimum life isn’t guaranteed.

    Our solution (which is going through some release approval stages internally) is to simply limit the creation of the session to the Login page. That’s a page that should not be cached and thus setting a cookie while on it (i.e. modifying headers) shouldn’t be an issue.

    We were considering offering a shortcode for our login button, but because of the performance implications brought up by this thread, we’re rethinking the operation of that button.

    That said, @deltafactory, we’re always willing to look at patches, or you’re welcome to start an issue to discuss a proposed patch on our GitHub repo for this.

    deltafactory

    (@deltafactory)

    If implemented as a replacement for the CSRF authenticator, the nonce isn’t used to authenticate or authorize. It’s used as a secret component to prevent cross-site forgery. Said another way, knowing the nonce value doesn’t grant access to a resource on its own.

    In any case, it does exactly what you want: generate a “short-lived” repeatable random value, without additional persistence requirements.

    FWIW, hosting providers frown upon Sessions and I thought I recalled WPEngine disabling them entirely. I imagine setting the value to a cookie would reduce security.

    Rob W

    (@robertark)

    Hi all,

    I agree with the solution on only implementing sessions and cookies when necessary. Any authenticated user would always bypass caching mechanisms in our case.

    Otherwise, we need to be serving cached pages from POPs – something which is not possible when the client is receiving and sending cookies.

    To Deltafactory’s point, Pantheon frowns on using native php session functions over using wp’s session handler as it’s abstracted. I think if Amazon’s update includes using the wp session class and only spawning a session where necessary, it will resolve a lot of issues.

    Thanks guys!

    deltafactory

    (@deltafactory)

    Just to clarify something that’s poorly documented within WordPress, the WP Sessions that were introduced relatively recently only track different login instances of the same user across browsers. I believe the session ID *does* factor into the generation of a nonce so that the same user’s nonce across browsers will be different.

    What it doesn’t do is provide a replacement for PHP Sessions in the form of persistent key/value storage. Many in the community have been pushing for such a mechanism, as implemented here (https://wordpress.org/plugins/wp-session-manager/), a related implementation that’s bundled with WooCommerce, and probably others as well.

    I’ll be implementing the session-less, wp_nonce-based approach since it solves this exact problem. I’m open to further discussion of security concerns.

    deltafactory

    (@deltafactory)

    @robertark, some of the adjustments discussed are implemented here.

    https://github.com/deltafactory/login-with-amazon-wordpress

    I’m also starting to think through the changes and process to link an existing user to an Amazon account regardless of email address on file.

    Rob W

    (@robertark)

    Hi @deltafactory

    Nonces still use sessions, correct? It appears that the plugin will still spawn a session on every page load due to the wp_footer action being called (such as the login button being on every page).

    How can we get around this?

    If a session is sent, a cookie is created. The client then sends the cookie with future requests and causes Varnish to bypass cache hits.

    Thoughts?

    deltafactory

    (@deltafactory)

    The WP nonces use a number of components including a timestamp to generate a unique, randomized value that changes over time. We avoid the need to store that component because we can algorithmically regenerate it.

    Forgive me for not being clear: the WP Session that is used is not the same thing as a PHP Session. WordPress itself does not use PHP Sessions. Are you still seeing session cookies created when using my fork?

    I expect to be testing the changes in my repo (including future enhancements) next week, so feel free to follow along there.

    deltafactory

    (@deltafactory)

    There’s a flaw with my approach, and a possible solution:

    It’s true that WP Nonces use information about the current user session to generate the value. However, in this case there is no user and the anonymous context is the same for everyone. At a given moment in time, the nonce for all unauthorized users would be the same.

    The solution would be to use a Session cookie, not a PHP session. The value of the cookie would be another component used to generate the WP Nonce.

    The next concern would be that this value is accessible from the browser. However, PHPSESSID cookies have the same exact issue.

    Hello @login-with-amazon

    Just curious to see how everything’s going. Would love to get varnish up and working again 🙂

    Also, I wanted to point out that we’re using the “Login with Amazon” button on all pages – which we’re calling the JS function addLoginToForm manually through our own scripts.

    Plugin Author login-with-amazon

    (@login-with-amazon)

    Sorry, had a lot of traveling last couple of weeks.

    Just reviewed @deltafactory‘s updated code. It fixed the nonce uniqueness/persistence issues, but brought back the problem of setting a cookie the moment the user hits the site (which can impact caching).

    Discussing on: https://github.com/amzn/login-with-amazon-wordpress/pull/3

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Improper use of sessions’ is closed to new replies.