Skip to content

Commit 7e93669

Browse files
authored
Send a wordpress-specific user agent (#78)
1 parent af2442d commit 7e93669

3 files changed

Lines changed: 39 additions & 8 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"require": {
1414
"composer/installers": "~1.0",
15-
"duosecurity/duo_universal_php": ">=1.1.0"
15+
"duosecurity/duo_universal_php": ">=1.1.1"
1616
},
1717
"require-dev": {
1818
"phpunit/phpunit": "^9.0",

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

duouniversal-wordpress.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,35 @@
6161
$utils
6262
);
6363

64+
/**
65+
* Extend User Agent string with WordPress-specific information
66+
*/
67+
function duo_extend_user_agent() {
68+
global $duo_client, $utils;
69+
70+
if ( $duo_client && $utils && $utils->duo_auth_enabled() ) {
71+
try {
72+
if ( ! function_exists( 'get_plugin_data' ) ) {
73+
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
74+
}
75+
$plugin_data = get_plugin_data( __FILE__ );
76+
$plugin_version = $plugin_data['Version'];
77+
78+
global $wp_version;
79+
80+
$user_agent_extension = sprintf(
81+
'duo_universal_wordpress/%s (wordpress_version=%s)',
82+
$plugin_version,
83+
$wp_version
84+
);
85+
86+
$duo_client->appendToUserAgent( $user_agent_extension );
87+
} catch ( Exception $e ) {
88+
$utils->duo_debug_log( $e->getMessage() );
89+
}
90+
}
91+
}
92+
6493
if ( ! \is_multisite() ) {
6594
$plugin_name = plugin_basename( __FILE__ );
6695
add_filter( 'plugin_action_links_' . $plugin_name, array( $settings, 'duo_add_link' ), 10, 2 );
@@ -75,6 +104,8 @@
75104

76105
/*-------------Register WordPress Hooks-------------*/
77106

107+
\add_action( 'init', 'duo_extend_user_agent' );
108+
78109
\add_action( 'init', array( $duoup_plugin, 'duo_verify_auth' ), 10 );
79110

80111
\add_action( 'clear_auth_cookie', array( $duoup_plugin, 'clear_current_user_auth' ), 10 );

0 commit comments

Comments
 (0)