You should never directly work with the WordPress global variables, and it's bad practice to do so.
Use wp_get_current_user: https://codex.wordpress.org/Function_Reference/wp_get_curren...
The largest attack surface for WP is poorly developed plugins and themes, not WordPress core.