Krzysiek Dróżdż
krzysiek@wpmagus.pl
WPmagus.pl
Interfejs do łatwego wybierania informacji ze strony pomijając warstwę prezentacji.
Znajdziecie je tutaj:
/wp-json/
Tak, bo od 4.7 każdy to ma włączone
Tak naprawdę, to wcześniej, ale od 4.7 coś można z tym zrobić.
żródło: www.wpwhitesecurity.com
żródło: www.wpwhitesecurity.com
Spójrzmy w kod i poznajmy skutki pewnych drobnych nieostrożności…
/wp-json/wp/v2/users
Ale slug, to nie login!
// Filters for WP-API version 1.x
add_filter( 'json_enabled', '__return_false' );
add_filter( 'json_jsonp_enabled', '__return_false' );
// Filters for WP-API version 2.x
add_filter( 'rest_enabled', '__return_false' );
add_filter( 'rest_jsonp_enabled', '__return_false' );
// Remove REST API info from head and headers
remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'template_redirect', 'rest_output_link_header', 11 );
function allow_logged_in_rest_access( $access ) {
if( ! is_user_logged_in() ) {
return new WP_Error(
'rest_cannot_access',
__( 'Only authenticated users can access the REST API.', '...' ),
array( 'status' => rest_authorization_required_code() )
);
}
return $access;
}
add_filter( 'rest_authentication_errors', 'allow_logged_in_rest_access' );
function unregister_users_endpoints( $endpoints ) {
if ( isset( $endpoints['/wp/v2/users'] ) ) {
unset( $endpoints['/wp/v2/users'] );
}
});
add_filter( 'rest_endpoints', 'unregister_users_endpoints' );
RewriteCond %{REQUEST_METHOD} ^(GET|POST|PUT|PATCH|DELETE) [NC]
RewriteCond %{REQUEST_URI} ^.*wp-json/wp/ [NC]
RewriteRule ^(.*)$ - [F]
Krzysiek Dróżdż
krzysiek@wpmagus.pl
WPmagus.pl