Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
wp_specialchars() vs attribute_escape() ( now esc_attr() ) and quote entity-encoding
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mark Jaquith  
View profile  
 More options May 9 2009, 4:36 am
From: Mark Jaquith <markjaqu...@gmail.com>
Date: Sat, 9 May 2009 04:36:21 -0400
Local: Sat, May 9 2009 4:36 am
Subject: [wp-hackers] wp_specialchars() vs attribute_escape() ( now esc_attr() ) and quote entity-encoding
WordPress 2.8 is getting a shortening, consolidation, and
"i18n-chaining" upgrade for its security escaping functions.

Here are some old/new pairs:

echo attribute_escape( __('Translated String') );
esc_attr_e(' Translated String' );

attribute_escape( __('Translated String' ) );
esc_attr__( 'Translated String' );

attribute_escape( $user_string );
esc_attr( $user_string );

js_escape( "dynamic $js" );
esc_js( "dynamic $js" );

The naming convention is esc_FORMAT[optional i18n suffix](). It's
shorter, predictable, and it cuts down on parenthesis nesting! Next on
my list was one-parameter wp_specialchars(), which will become
esc_html(), esc_html_e() and esc_html__().

It occurred to me that a lot of people do this:

<input value="<?php echo wp_specialchars( $xss ); ?>" />

Which is WRONG (and unfortunately common in plugins) and an XSS
exploit opportunity. See, attribute_escape() (now esc_attr())
additionally entity-encodes quotes, to prevent XSS attacks from
"breaking out" of the attribute. That's the only real difference
between attribute_escape( $xss ) and wp_specialchars( $xss ). While it
is dangerous to use wp_specialchars( $xss ) instead of
attribute_escape( $xss ), the opposite is not true. There is no harm,
that I can think of, in entity-encoding quotes in an HTML context.

Can you think of any? If not, this presents us with an opportunity to
make esc_html() and esc_attr() functionally equivalent and to have
wp_specialchars( $xss ) calls go through esc_html(), which would
encode quotes, and thus anyone who used the above code would get a
free security upgrade to their plugin/theme. Can you think of any
reason this wouldn't work? C'mon, go ahead and rain on my parade.

Notes:

Backward compat with the old functions is maintained. As for my
proposed handling of esc_html() and wp_specialchars(), calls to
wp_specialchars() with default values for the rarely-used additional
params would be honored, like before. It's only single-parameter calls
to wp_specialchars() that would get the esc_html()/quote-encoding
treatment.

--
Mark Jaquith
http://markjaquith.com/
http://coveredwebservices.com/
_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron D. Campbell  
View profile  
 More options May 14 2009, 2:11 pm
From: "Aaron D. Campbell" <aa...@xavisys.com>
Date: Thu, 14 May 2009 11:11:16 -0700
Local: Thurs, May 14 2009 2:11 pm
Subject: Re: [wp-hackers] wp_specialchars() vs attribute_escape() ( now esc_attr() ) and quote entity-encoding
I recently put up a WordPress based site for Harvard Law, and they are
REALLY strict about XSS (they have an IBM scanning tool that they use
regularly to detect this stuff).  Heavy usage of attribute_escape helped
a LOT.  I can't think of any reason not to enforce the additional level
of security (for now at least...but I'll continue to think on it).  I
actually think it's a great idea.

_______________________________________________
wp-hackers mailing list
wp-hack...@lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »