Skip to content

Instantly share code, notes, and snippets.

@mrclay
mrclay / AjaxForm.js
Created November 11, 2015 01:37
Sets up Drupal so that any form can be fetched and submitted over Ajax. Unlike Drupal's ajax module, there are no modifications required to the form at all. Even redirects are captured and sent back to the client.
/**
* Notes:
* - This is not the complete JS module
*/
/**
* An object to simplify fetching Drupal forms via Ajax
*
* @param {object} spec Object with keys:
*
@mrclay
mrclay / elgg-profile-queries.php
Last active October 21, 2015 17:10
Elgg: profile MySQL queries on Elgg 1.10 - 1.x
<?php
/**
* Query profiler for Elgg 1.10-1.12
*
* Require this script inside settings.php and the JavaScript console will report all
* queries with their time in seconds, and the total time spent in mysql_query().
*
* This will not include queries performed after the "output", "page" hook.
*
* On production you could include this only if a particular query string is set:

More details on the WordPress XSS vulnerability found by Klikki. Both real exploits include a style attribute to widen the mouseover area to the whole viewport; I've left it out here to keep it simple.

The exploit comment is valid HTML and won't be altered by an HTML santizer:

<a title='x onmouseover=alert(unescape(/hello%20world/.source)) AAAAAAAAAAAA...[64 kb]..AAA'></a>

But once truncated by MySQL, the comment will become malformed HTML (note the attribute is left open):

<a title='x onmouseover=alert(unescape(/hello%20world/.source)) AAAAAAAAAAA
@mrclay
mrclay / runsAfter.js
Created January 19, 2015 19:25
Jasmine helper to cleanup tests that have async operations without a callback.
/**
* Jasmine helper: Call func sequentially after blocking for {delay} milliseconds
*
* @param {Number} delay
* @param {Function} func
*
* @link http://jasmine.github.io/1.3/introduction.html#section-Asynchronous_Support
*/
function runsAfter(delay, func) {
var blocking = true;
@mrclay
mrclay / elgg_mem.php
Created November 28, 2014 14:54
Elgg: Graph memory usage loading a large number of entities
<?php
require __DIR__ . '/engine/start.php';
global $ENTITY_CACHE;
_elgg_services()->db->disableQueryCache();
$md_cache = _elgg_services()->metadataCache;
$mem_initial = 0;
$show_mem_delta = function () use (&$mem_initial) {
@mrclay
mrclay / elgg_prune_entities.sql
Last active August 29, 2015 14:09
Elgg: Delete entity rows where the associated secondary table rows no longer exist
DELETE FROM elgg_entities
WHERE guid in (
SELECT * FROM (
SELECT e.guid FROM elgg_entities AS e
LEFT JOIN elgg_users_entity AS u ON (e.guid = u.guid)
WHERE e.type = 'user'
AND u.guid IS NULL
) AS q1
UNION
SELECT * FROM (
@mrclay
mrclay / annotation_test.php
Created October 6, 2014 14:02
Help me determine the best-supported flavor of variable annotations across PHP IDEs.
<?php
/**
* Help me determine the best-supported flavor of variable annotations across PHP IDEs.
*
* 1. Open this file in your IDE
*
* 2. Place your cursor at the bottom of the file and see which variables are understood
* as instances of the class Foo
*
* 3. Report your findings to http://goo.gl/forms/qBO8OpLPlj
@mrclay
mrclay / xss_check.html
Created September 26, 2014 18:27
Basic XSS locator that also includes tests for insecure use of html_entity_decode
"><script>alert(1)</script>"&gt;&lt;script&gt;alert(2)&lt;/script&gt;
@mrclay
mrclay / site_lock.php
Created September 13, 2014 20:17
Scripts to take an Elgg 1.9 site down so that plugins can be added/removed without them being booted
<?php
/**
* Place a site in maintenance mode, disable caches, and disable plugin boot.
*/
if (php_sapi_name() !== "cli") {
exit;
}
require __DIR__ . '/engine/start.php';
@mrclay
mrclay / Enums_Base.php
Last active August 29, 2015 14:05
Enum types in PHP. This is the closest thing to the Java model (each value is an instance) I could get with good IDE usability.
<?php
namespace Enums;
/**
* Base class for an Enum type where each value is a class instance. Possible values are
* parsed from PHPdoc comments (must be static methods that return the type and are all caps)
*/
abstract class Base {