Skip to content

Instantly share code, notes, and snippets.

@alexkolson
Created December 15, 2010 07:20
Show Gist options
  • Save alexkolson/741730 to your computer and use it in GitHub Desktop.
Save alexkolson/741730 to your computer and use it in GitHub Desktop.
ruleset a369x117 {
meta {
name "Clownhat JS"
description <<
Clownhat JS
>>
author "AKO"
logging on
}
rule clownhats_are_hip_all_the_cool_kids_are_wearing_them {
select when pageview ".*"
{
emit <|
var userId = /\/users\/([0-9]*)\//.exec("/users/230948/coolio")[1];
alert(userId);
|>;
}
}
}
ruleset a369x118 {
meta {
name "Heredoc JS"
description <<
Heredoc JS
>>
author "AKO"
logging on
}
rule clownhats_are_not_hip_only_dorky_kids_wear_them {
select when pageview ".*"
{
emit <<
var userId = /\/users\/([0-9]*)\//.exec("/users/230948/coolio")[1];
alert(userId);
>>;
}
}
}
ruleset a369x117 {
meta {
name "Clownhat JS"
description <<
Clownhat JS
>>
author "AKO"
logging on
}
rule clownhats_are_hip_all_the_cool_kids_are_wearing_them {
select when pageview ".*"
{
emit <|
var userId = /\/users\/([0-9]*)\/\s?/.exec("/users/230948/coolio")[1]; // notice optional space clause. This makes clownhat escaping mechanism work.
alert(userId);
|>;
}
}
}
// 2010/12/15 00:05:20 DEBUG Rules.pm a369x117 [global] Found 1 rules for RID a369x117
// 2010/12/15 00:05:20 DEBUG Events.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Adding to schedule: a369x117 & clownhats_are_hip_all_the_cool_kids_are_wearing_them
// 2010/12/15 00:05:20 DEBUG Scheduler.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Schedule iterator returning clownhats_are_hip_all_the_cool_kids_are_wearing_them with current RID count 0 and current rule count 1
// 2010/12/15 00:05:20 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Getting ruleset a369x117 for http://example.com/
// 2010/12/15 00:05:20 DEBUG Repository.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Using cached ruleset for a369x117 (dev) with key ruleset:dev:a369x117 & optimization version 7
// 2010/12/15 00:05:20 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Found 1 rules for RID a369x117
// 2010/12/15 00:05:20 INFO Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Processing rules for site a369x117
// 2010/12/15 00:05:20 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Global vars:
// 2010/12/15 00:05:20 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Rule clownhats_are_hip_all_the_cool_kids_are_wearing_them is active
// 2010/12/15 00:05:20 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them [selected] clownhats_are_hip_all_the_cool_kids_are_wearing_them
// 2010/12/15 00:05:20 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them
//------------------- begin rule execution: clownhats_are_hip_all_the_cool_kids_are_wearing_them ------------------------
// 2010/12/15 00:05:20 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Rule not pre optimized...
// 2010/12/15 00:05:20 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them [rules::optimize_pre] foreach vars:
// 2010/12/15 00:05:20 INFO Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them fired
// 2010/12/15 00:05:20 DEBUG Actions.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them blocktype is every
// 2010/12/15 00:05:20 DEBUG Actions.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them actions list contains 1 actions
// 2010/12/15 00:05:20 DEBUG Scheduler.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Moving to next RID
// 2010/12/15 00:05:20 DEBUG Scheduler.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Resetting schedule
// 2010/12/15 00:05:20 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Finished processing rules for a369x117
// 2010/12/15 00:05:20 DEBUG AST.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Generating JS for a369x117
// 2010/12/15 00:05:20 DEBUG AST.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Generating resource statement for a369x117
// 2010/12/15 00:05:20 DEBUG Log.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them [logging] Storing logging data for a369x117
// 2010/12/15 00:05:20 DEBUG Log.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them results for clownhats_are_hip_all_the_cool_kids_are_wearing_them
// 2010/12/15 00:05:20 DEBUG Log.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them TXN_ID: ADB0A63E-0819-11E0-A499-5DD2193CA6C2
// 2010/12/15 00:05:20 DEBUG Session.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Cleaning up session
// 2010/12/15 00:05:20 INFO Response.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Event processing finished
// 2010/12/15 00:05:20 DEBUG Response.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them __FLUSH__
// 2010/12/15 00:05:20 DEBUG Response.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Called with GET /blue/event/web/pageview/a369x117/129239669226113670802120353331?kvars=%7B%7D&caller=http%3A%2F%2Fexample.com%2F&referer=&title=Example+Web+Page&a369x117:kynetx_app_version=dev HTTP/1.0
// 2010/12/15 00:05:20 DEBUG Response.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Returning javascript from evaluation
// KNS Wed Dec 15 07:05:20 2010
KOBJ.registerClosure('a369x117', function($K) { (function(){(function(){function callBacks () {
};
var userId = /\/users\/([0-9]*)\
alert(userId);
;
callBacks();
}());
}());
KOBJ.logVerify = KOBJ.logVerify || function(t,a,c){};KOBJ.logVerify('ADB0A63E-0819-11E0-A499-5DD2193CA6C2', 'a369x117', 'cs.kobj.net'); }, '129239669226113670802120353331');
// 2010/12/15 00:09:27 DEBUG Rules.pm a369x118 [global] Found 1 rules for RID a369x118
// 2010/12/15 00:09:27 DEBUG Events.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Adding to schedule: a369x118 & clownhats_are_not_hip_only_dorky_kids_wear_them
// 2010/12/15 00:09:27 DEBUG Scheduler.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Schedule iterator returning clownhats_are_not_hip_only_dorky_kids_wear_them with current RID count 0 and current rule count 1
// 2010/12/15 00:09:27 DEBUG Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Getting ruleset a369x118 for http://example.com/
// 2010/12/15 00:09:27 DEBUG Repository.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Using cached ruleset for a369x118 (dev) with key ruleset:dev:a369x118 & optimization version 7
// 2010/12/15 00:09:27 DEBUG Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Found 1 rules for RID a369x118
// 2010/12/15 00:09:27 INFO Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Processing rules for site a369x118
// 2010/12/15 00:09:27 DEBUG Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Global vars:
// 2010/12/15 00:09:27 DEBUG Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Rule clownhats_are_not_hip_only_dorky_kids_wear_them is active
// 2010/12/15 00:09:27 DEBUG Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them [selected] clownhats_are_not_hip_only_dorky_kids_wear_them
// 2010/12/15 00:09:27 DEBUG Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them
//------------------- begin rule execution: clownhats_are_not_hip_only_dorky_kids_wear_them ------------------------
// 2010/12/15 00:09:27 DEBUG Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Rule not pre optimized...
// 2010/12/15 00:09:27 DEBUG Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them [rules::optimize_pre] foreach vars:
// 2010/12/15 00:09:27 INFO Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them fired
// 2010/12/15 00:09:27 DEBUG Actions.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them blocktype is every
// 2010/12/15 00:09:27 DEBUG Actions.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them actions list contains 1 actions
// 2010/12/15 00:09:27 DEBUG Scheduler.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Moving to next RID
// 2010/12/15 00:09:27 DEBUG Scheduler.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Resetting schedule
// 2010/12/15 00:09:27 DEBUG Rules.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Finished processing rules for a369x118
// 2010/12/15 00:09:27 DEBUG AST.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Generating JS for a369x118
// 2010/12/15 00:09:27 DEBUG AST.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Generating resource statement for a369x118
// 2010/12/15 00:09:27 DEBUG Log.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them [logging] Storing logging data for a369x118
// 2010/12/15 00:09:27 DEBUG Log.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them results for clownhats_are_not_hip_only_dorky_kids_wear_them
// 2010/12/15 00:09:27 DEBUG Log.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them TXN_ID: 4122639E-081A-11E0-AADC-5B0EA56309D5
// 2010/12/15 00:09:27 DEBUG Session.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Cleaning up session
// 2010/12/15 00:09:27 INFO Response.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Event processing finished
// 2010/12/15 00:09:27 DEBUG Response.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them __FLUSH__
// 2010/12/15 00:09:27 DEBUG Response.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Called with GET /blue/event/web/pageview/a369x118/12923969532938822108589445709?kvars=%7B%7D&caller=http%3A%2F%2Fexample.com%2F&referer=&title=Example+Web+Page&a369x118:kynetx_app_version=dev HTTP/1.0
// 2010/12/15 00:09:27 DEBUG Response.pm a369x118 clownhats_are_not_hip_only_dorky_kids_wear_them Returning javascript from evaluation
// KNS Wed Dec 15 07:09:27 2010
KOBJ.registerClosure('a369x118', function($K) { (function(){(function(){function callBacks () {
};
var userId = /\/users\/([0-9]*)\//.exec("/users/230948/coolio")[1];
alert(userId);
;
callBacks();
}());
}());
KOBJ.logVerify = KOBJ.logVerify || function(t,a,c){};KOBJ.logVerify('4122639E-081A-11E0-AADC-5B0EA56309D5', 'a369x118', 'cs.kobj.net'); }, '12923969532938822108589445709');
// 2010/12/15 00:31:54 DEBUG Rules.pm a369x117 [global] Found 1 rules for RID a369x117
// 2010/12/15 00:31:54 DEBUG Events.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Adding to schedule: a369x117 & clownhats_are_hip_all_the_cool_kids_are_wearing_them
// 2010/12/15 00:31:54 DEBUG Scheduler.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Schedule iterator returning clownhats_are_hip_all_the_cool_kids_are_wearing_them with current RID count 0 and current rule count 1
// 2010/12/15 00:31:54 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Getting ruleset a369x117 for http://example.com/
// 2010/12/15 00:31:54 DEBUG Repository.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Using cached ruleset for a369x117 (dev) with key ruleset:dev:a369x117 & optimization version 7
// 2010/12/15 00:31:54 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Found 1 rules for RID a369x117
// 2010/12/15 00:31:54 INFO Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Processing rules for site a369x117
// 2010/12/15 00:31:54 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Global vars:
// 2010/12/15 00:31:54 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Rule clownhats_are_hip_all_the_cool_kids_are_wearing_them is active
// 2010/12/15 00:31:54 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them [selected] clownhats_are_hip_all_the_cool_kids_are_wearing_them
// 2010/12/15 00:31:54 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them
//------------------- begin rule execution: clownhats_are_hip_all_the_cool_kids_are_wearing_them ------------------------
// 2010/12/15 00:31:54 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Rule not pre optimized...
// 2010/12/15 00:31:54 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them [rules::optimize_pre] foreach vars:
// 2010/12/15 00:31:54 INFO Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them fired
// 2010/12/15 00:31:54 DEBUG Actions.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them blocktype is every
// 2010/12/15 00:31:54 DEBUG Actions.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them actions list contains 1 actions
// 2010/12/15 00:31:54 DEBUG Scheduler.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Moving to next RID
// 2010/12/15 00:31:54 DEBUG Scheduler.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Resetting schedule
// 2010/12/15 00:31:54 DEBUG Rules.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Finished processing rules for a369x117
// 2010/12/15 00:31:54 DEBUG AST.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Generating JS for a369x117
// 2010/12/15 00:31:54 DEBUG AST.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Generating resource statement for a369x117
// 2010/12/15 00:31:54 DEBUG Log.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them [logging] Storing logging data for a369x117
// 2010/12/15 00:31:54 DEBUG Log.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them results for clownhats_are_hip_all_the_cool_kids_are_wearing_them
// 2010/12/15 00:31:54 DEBUG Log.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them TXN_ID: 63F05AC2-081D-11E0-9E53-AFD2193CA6C2
// 2010/12/15 00:31:54 DEBUG Session.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Cleaning up session
// 2010/12/15 00:31:54 INFO Response.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Event processing finished
// 2010/12/15 00:31:54 DEBUG Response.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them __FLUSH__
// 2010/12/15 00:31:54 DEBUG Response.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Called with GET /blue/event/web/pageview/a369x117/12923973071246014942439595318?kvars=%7B%7D&caller=http%3A%2F%2Fexample.com%2F&referer=&title=Example+Web+Page&a369x117:kynetx_app_version=dev HTTP/1.0
// 2010/12/15 00:31:54 DEBUG Response.pm a369x117 clownhats_are_hip_all_the_cool_kids_are_wearing_them Returning javascript from evaluation
// KNS Wed Dec 15 07:31:54 2010
KOBJ.registerClosure('a369x117', function($K) { (function(){(function(){function callBacks () {
};
var userId = /\/users\/([0-9]*)\/\s?/.exec("/users/230948/coolio")[1];
alert(userId);
;
callBacks();
}());
}());
KOBJ.logVerify = KOBJ.logVerify || function(t,a,c){};KOBJ.logVerify('63F05AC2-081D-11E0-9E53-AFD2193CA6C2', 'a369x117', 'cs.kobj.net'); }, '12923973071246014942439595318');
@alexkolson
Copy link
Author

Notice how when we add an optional space, or "\s?" to the regular expression, the clownhats work fine. We really could've added any valid regular expression statement there and it would return to valid js. What I think is happening is that the heredoc emit syntax, in the process of converting it to a string and then to JS is properly handling the '' and '/' characters, while the straight-up clownhat emit is not. SO THE REAL PROBLEM IS WITH HOW THE CLOWNHAT SYNTAX HANDLES ESCAPES. (Not shouting, just drawing attention there.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment