VIP Go: Two-Step Authentication Required for Admins

Starting Monday November 14th, two-step authentication will be required for all admins on VIP Go sites via Jetpack SSO. If you have sites on the WordPress.com VIP platform, you’ll remember that two-step authentication has been a requirement for admin users for some time. For any sites using a conflicting SSO plugin, we’ll work with your developers to ensure admin users have two-step authentication enabled as well.

The new requirement will be enforced for admins by default, but will be possible to expand to all users via a filter. We’ll follow up with details following the November 14th deadline.

In the meantime, we recommend ensuring all admin users on your sites have enabled two-step authentication on their WordPress.com account before November 14th. If you try to log into a VIP Go site as an admin with an account that does not have two-step authentication set up, you’ll be directed to the security settings page on WordPress.com.

 

screen-shot-2016-10-19-at-2-03-35-pm

VIP Themes in the WordPress.com REST API

Today we’re announcing additional functionality for VIP themes in the WordPress.com REST API. Previously, the REST API didn’t load VIP themes which meant custom post types, custom taxonomies, and custom user roles were absent there. For the past couple weeks we’ve been testing VIP themes in the REST API and today that functionality is available for all VIP sites.

For the most part, this will work just as you would expect. REST API specific filters, like rest_api_allowed_post_types will now be in effect. If your theme was already using some of the REST API filters, you may want to check that they’re functioning as expected. It is now even more important to be careful of theme constants like STYLESHEETPATH and TEMPLATEPATH as they’re not available in the REST API context.

If you have any questions about using the WordPress.com REST API, let us know!

Preventing XSS in JavaScript

The primary vulnerability we need to be careful of in Javascript is Cross Site Scripting (XSS). We’re probably all familiar with the escaping functions we use with PHP in WordPress to avoid that — esc_html(), esc_attr(), esc_url(), etc. Given that, it only seems natural that we would also need to escape HTML in Javascript.

As it turns out out, however, that’s the wrong way to approach Javascript security. To avoid XSS, we want to avoid inserting HTML directly into the document and instead, programmatically create DOM nodes and append them to the DOM. This means avoiding .html(), .innerHTML, and other related functions, and instead using .append(), .prepend(), .before(), .after(), and so on.

Here is an example:

jQuery.ajax({
    url: 'http://any-site.com/endpoint.json'
}).done( function( data ) {
    var link = '<a href="' + data.url + '">' + data.title + '</a>';

    jQuery( '#my-div' ).html( link );
});

This approach is dangerous, because we’re trusting that the response from any-site.com includes only safe data – something we can not guarantee, even if the site is our own. Who is to say that data.title doesn’t contain <script>alert( "haxxored");</script>;?

Instead, the correct approach is to create a new DOM node programmatically, then attach it to the DOM:

jQuery.ajax({
    url: 'http://any-site.com/endpoint.json'
}).done( function( data ) {
    var a = jQuery( '<a />' );
    a.attr( 'href', data.url );
    a.text( data.title );

    jQuery( '#my-div' ).append( a );
});

Note: It’s technically faster to insert HTML, because the browser is optimized to parse HTML. The best solution is to minimize insertions of DOM nodes by building larger objects in memory then insert it into the DOM all at once, when possible.

By passing the data through either jQuery or the browser’s DOM API’s, we ensure the values are properly sanitized and remove the need to inject insecure HTML snippets into the page.

To ensure the security of your application, use the DOM APIs provided by the browser (or jQuery) for all DOM manipulation.

Escaping Dynamic JavaScript Values

When it comes to sending dynamic data from PHP to JavaScript, care must be taken to ensure values are properly escaped. The core function esc_js() helps escape JavaScript for us in DOM attributes, while all other values should be encoded with wp_json_encode().

From the WP Codex on esc_js():

It is intended to be used for inline JS (in a tag attribute, for example onclick=”…”).

If you’re not working with inline JS in HTML event handler attributes, a more suitable function to use is wp_json_encode, which is built-in to WordPress.

This approach is incorrect:

var title = '<?php echo esc_js( $title ); ?>';
var content = '<?php echo esc_js( $content ); ?>';
var comment_count = '<?php echo esc_js( $comment_count ); ?>';

Instead, it’s better to use wp_json_encode() (note that wp_json_encode() adds the quotes automatically):

var title = <?php echo wp_json_encode( $title ); ?>;
var content = <?php echo wp_json_encode( $content ); ?>;
var comment_count = <?php echo wp_json_encode( $comment_count ); ?>;

Stripping Tags

It may be tempting to use .html() followed by .text() to strip tags – but this approach is still vulnerable to attack:

// Incorrect
var text = jQuery('<div />').html( some_html_string ).text();
jQuery( '.some-div' ).html( text );

Setting the HTML of an element will always trigger things like src attributes to be executed, which can lead to attacks like this:

// XSS attack waiting to happen
var some_html_string = '<img src="a" onerror="alert(\'haxxored\');" />';

As soon as that string is set as a DOM element’s HTML (even if it’s not currently attached to the DOM!), src will be loaded, will error out, and the code in the onerror handler will be executed…all before .text() is ever called.

The need to strip tags is indicative of bad practices – remember, always use the appropriate API for DOM manipulation.

// Correct
jQuery( '.some-div' ).text( some_html_string );

Other Common XSS Vectors

  • Using eval(). Never do this.
  • Un-whitelisted / un-sanitized data from urls, url fragments, query strings, cookies
  • Including un-trusted / un-reviewed 3rd party JS libraries
  • Using out-dated / un-patched 3rd party JS libraries

Helpful Resources

Update to Guest Author Management

If you use Co-Authors-Plus, you may have wondered why the Guest Authors menu is a submenu of Tools instead of Users on WordPress.com. Without going into too much detail, there were some conflicts with WordPress.com user profiles and Co-Authors that led us to relocate that menu. Those issues have since been resolved and we’re happy to be moving the Guest Authors menu back to its natural position as a submenu of Users.

asiFSutd1k-3000x3000

If you’d like to keep it as a submenu of Tools, you can do so by adding the following line of code to your theme:

add_filter( 'coauthors_guest_author_parent_page', function() { return 'tools.php'; } );

Notice: VIP Quickstart Updates

The most recent update to VIP Quickstart changes the installation process slightly for local installations. In most cases, the process got even simpler. Please refer to the Getting Started guide for updated installation instructions.

The background for these changes is a set of technologies referred to as zeroconf — short for zero-configuration networking. In OS X this is implemented as Bonjour. In short, we’re able to use Bonjour to automatically detect the domain of Quickstart, which will now (almost) always be vip.local if you’re running it in Vagrant. If you’re not an OS X user, don’t worry as there are options for using zeroconf on Windows and Linux as well. For anyone that’s currently running Quickstart on a different domain, this will continue to work as long as you leave the hosts file configured the way it is.

One of the advantages of zeroconf is that we don’t have to make any hosts file changes. We’ll be able to take advantage of this in the future by using subdomains instead of subdirectories in multisite.

VIP Quickstart Updates

Last year we introduced VIP Quickstart to give VIP developers an environment that emulates WordPress.com. We recently added functionality to Quickstart that brings it even closer to mirroring WordPress.com.

First, we added the same Javascript and CSS concatenation that WordPress.com uses to Quickstart. Due to the way Javascript parsers work, certain bugs were masked until the scripts were concatenated. This change makes it easier to spot these issues before they’re deployed to production.

We also added warnings for large option values. Since Memcache values can’t be larger than 1MB, exceeding that in options can cause a site to break. We have logic on WordPress.com to block sites with option values greater than 1MB. Now that same logic lives in Quickstart!

We develop Quickstart in the open, on Github. You can follow along there. And of course, we welcome pull requests!

Introducing WP-CLI Helpers for VIP

Occasionally, you may find you need to access or transform data on your WordPress.com site. For more than a dozen or so posts, it’s often more efficient to write what we call a “bin script.” In writing a bin script, you can easily change strings, assign categories, or add post meta across hundreds or thousands of posts. To keep your scripts as lean and mean as possible, we highly encourage you to leverage WP-CLI, an awesome community framework.

We’ve been using WP-CLI pretty extensively on VIP for some time now, and we recently introduced a new set of WP-CLI helpers for VIP with the WPCOM_VIP_CLI_Command class. You use this by extending it just like the standard WP_CLI_Command class. The only difference is that we’ll include some extra helper function specific to VIP. The first function is stop_the_insanity(), which is normally used between cycles in long running commands and prevents the system from running out of memory.

We hope this addition will make things easier for developers working on VIP. If you have suggestions for helper functions that you’d like to see added, let us know.

Now in Beta: Enforce Two-Step Authentication Across Your Network

Here at WordPress.com VIP, we have all sorts of magic behind the scenes to keep your sites safe and secure. However, it’s equally important that your users keep their logins safe by practicing security best practices.

Last year, we introduced Two-Step Authentication for WordPress.com accounts, making it dramatically more difficult for an account to be compromised. Many of our VIP customers have requested a way to enforce Two-Step Authentication for all users across their sites. We heard you.

Last week, we completed a new feature that allows you to enforce this rule so that users are treated as contributors (meaning they can’t publish anything or change options) unless they first enable Two-Step.

force 2fa

We are currently seeking beta testers to help us test this feature. If you’re interested, please let us know via vip-support@wordpress.com.

And, here’s a quick primer on our recommended security practices:

  1. Never give your password to anyone.
  2. Never use the same password twice. To help with managing passwords, use a program like 1Password or LastPass.
  3. Use high entropy passwords. If you are using a randomly generated password, it should be at least 24 characters and have numbers, mixed case letters, and symbols.
  4. Protect your computer with a password, and be sure to “lock” the screen anytime you step away from your machine.
  5. Use Two-Step Authentication!

More on security: Site and Security Monitoring Add-On.

Introducing: VIP Quickstart

Enterprise WordPress hosting, support, and consulting - WordPress VIP

Update:
VIP Quickstart is deprecated as of March 13, 2017. Support for Quickstart will continue through April 21, 2017. For new environments, we recommend using Chassis or VVV as detailed in the Local Environment documentation.

Previous Information:

One of the pain points we often see in the development process is getting a development environment set up. Today we’re introducing VIP Quickstart to fix that. The goal of VIP Quickstart is to provide an environment similar to what you would be deploying to on WordPress.com that’s also quick and easy to setup.

VIP Quickstart is a mix of Vagrant, Puppet, Bash scripts, and some PHP code that will help you quickstart your WordPress.com VIP development. The setup installs a base Ubuntu 12.04 box running PHP, Nginx, and MySQL. The WordPress installation will be WordPress multisite from the latest trunk build. It also includes the WordPress Developer plugin along with all…

View original post 178 more words