Security Advisories (1)
CVE-2026-12740 (2026-07-04)

Plack::Middleware::OAuth versions through 0.10 for Perl do not support the OAuth 2.0 state parameter. RequestTokenV2 builds the provider authorization redirect without issuing a state value, and AccessTokenV2 exchanges the callback code and registers the resulting token into the session (register_session) without verifying that the callback corresponds to an authorization request this session initiated. Any application that uses this middleware for OAuth 2.0 login is exposed to login cross-site request forgery: because the callback is not bound to the session that began the flow, an attacker who starts an authorization with their own provider account can deliver the resulting callback to a victim, causing the victim's session to complete the attacker's authorization and associating the attacker's provider identity and access token with that session. Where the application persists this as an account link, the attacker may retain access to the victim's account through their own provider credentials.

NAME

Plack::Middleware::OAuth - Plack middleware for OAuth1, OAuth2 and builtin provider configs.

DESCRIPTION

Plack::Middleware::OAuth supports OAuth1 and OAuth2, and provides builtin configs for providers like Twitter, Github, Google, Facebook. The only one thing you need to mount your OAuth service is to setup your consumer_key, consumer_secret (OAuth1) or client_id, client_secret, scope (OAuth2).

Plack::Middleware::OAuth generates authorize url (mount_path/provider_id) and auththorize callback url (mount_path/provider_id/callback). If the authorize path matches, then user will be redirected to OAuth provider to authorize your application.

For example, if you mount Plack::Middleware::OAuth on /oauth, then you can access http://youdomain.com/oauth/twitter to authorize, Plack::Middleware::OAuth will redirect you to Twitter, after authorized, then Twitter will redirect you to your callback url http://youdomain.com/oauth/twitter/callback.

For more details, please check the example psgi in eg/ directory.

SYNOPSIS

	use Plack::Builder;

	builder {

        mount '/oauth' => builder {
            enable 'OAuth', 

                on_signin => sub  { 
                    my ($self,$env,$oauth_data) = @_;
                    return [  200 , [ 'Content-type' => 'text/html' ] , 'Signin!' ];
                },

                on_error => sub {  ...  },

                providers => {

                    # capital case implies Plack::Middleware::OAuth::Twitter
                    # authorize path: /oauth/twitter
                    # authorize callback path: /oauth/twitter/callback

                    'Twitter' =>
                    {
                        consumer_key      => ...
                        consumer_secret   => ...
                    },

                    # captical case implies Plack::Middleware::OAuth::Facebook
                    # authorize path: /oauth/facebook
                    # authorize callback path: /oauth/facebook/callback

                    'Facebook' =>
                    {
                        client_id        => ...
                        client_secret           => ...
                        scope            => 'email,read_stream',
                    },

                    'Github' => 
                    {
                        client_id => ...
                        client_secret => ...
                        scope => 'user,public_repo'
                    },

                    'Google' =>  { 
                        client_id     => '',
                        client_secret => '',
                        scope         => 'https://www.google.com/m8/feeds/'
                    },

                    # authorize path: /oauth/custom_provider
                    # authorize callback path: /oauth/custom_provider/callback
                    'custom_provider' => { 
                        version => 1,
                        ....
                    }
			};
        };
		$app;
	};

The callback/redirect URL is set to {SCHEMA}://{HTTP_HOST}/{prefix}/{provider}/callback by default.

Sessions

You can get OAuth1 or OAuth2 access token from Session,

my $session = Plack::Session->new( $env );
$session->get( 'oauth.twitter.access_token' );
$session->get( 'oauth.twitter.access_token_secret' );

$session->get( 'oauth2.facebook.access_token' );
$session->get( 'oauth2.custom_provider' );

Specify Signin Callback

enable 'OAuth', 
    providers => { .... },
    on_signin => sub  { 
        my ($self,$env,$oauth_data) = @_;
        return [  200 , [ 'Content-type' => 'text/html' ] , 'Signin!' ];
    };

Without specifying on_signin, OAuth middleware will use YAML to dump the response data to page.

Handle Error

enable 'OAuth', 
    providers => { .... },
    on_error => sub {
        my ($self,$env,$provider,$config) = @_;

    };

Supported Providers

  • Google

  • Twitter

  • Facebook

  • Github

Reference

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 482:

'=item' outside of any '=over'

Around line 504:

'=item' outside of any '=over'