Jump to content


Photo

"Include" in Etomite


  • Please log in to reply
6 replies to this topic

#1 Christiane

Christiane

    Etomite Forum Fan

  • Member
  • Pip
  • 124 posts

Posted 01 August 2009 - 01:58 PM

I want to use some code against XSS, see http://www.erich-kachel.de/?p=638 :

    <?php 
    function uniord__($c) { 
        $h = ord($c{0}); 
        if ($h <= 0x7F) { 
            return $h; 
        } else if ($h < 0xC2) { 
            return false; 
        } else if ($h <= 0xDF) { 
            return ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F); 
        } else if ($h <= 0xEF) { 
            return ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6 
                                     | (ord($c{2}) & 0x3F); 
        } else if ($h <= 0xF4) { 
            return ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12 
                                     | (ord($c{2}) & 0x3F) << 6 
                                     | (ord($c{3}) & 0x3F); 
        } else { 
            return false; 
        } 
    } 
     
    /** 
     * Secures input string against XSS-attacks. 
     * Return value can be send to browser securely. 
     * supports single & multi byte UTF-8 
     */ 
    function SEQ_OUTPUT($string_ = '') { 
        $string = mb_convert_encoding($string_, "UTF-8", "7bit, UTF-7, UTF-8, UTF-16, ISO-8859-1, ASCII"); 
     
        $output = ''; 
     
        for ($i = 0; $i < mb_strlen($string); $i++)  { 
            if (preg_match('/([a-zA-Z0-9_.-])/', $string[$i])) { 
                $output .= $string[$i]; 
                continue; 
            } 
            $byte = ord($string[$i]); 
            if ($byte <= 127)  { 
                $length = 1; 
                $output .= sprintf("&#x%04s;", dechex(uniord__(mb_substr($string, $i, $length)))); 
            } else if ($byte >= 194 && $byte <= 223)  { 
                $length = 2; 
                $output .= sprintf("&#x%04s;", dechex(uniord__(mb_substr($string, $i, $length)))); 
            } else if ($byte >= 224 && $byte <= 239)  { 
                $length = 3; 
                $output .= sprintf("&#x%04s;", dechex(uniord__(mb_substr($string, $i, $length)))); 
            } else if ($byte >= 240 && $byte <= 244)  { 
                $length = 4; 
                $output .= sprintf("&#x%04s;", dechex(uniord__(mb_substr($string, $i, $length)))); 
            } 
        } 
     
        return $output; 
    } 
    ?> 

Code can be tested by
    echo SEQ_OUTPUT('プライバシー <script>alert(3)</script>'); 

It runs in the wanted way, but I wish to use the code in more than one snippet.
Therefore i have the question, if it is possible, that this code can be placed in a separated snippet and then embedded in the different calling snippets by some "include"-function?
In which way do i give the text-string to the xss-snippet and the output back to the calling snippet?


Thanks for help.
Christiane

#2 mikef

mikef

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,551 posts

Posted 01 August 2009 - 08:34 PM

You can call one snippet from another using the RunSnippet api call. There's minimal documentation in the documentation pages.

However the implementation falls foul of bugs in the snippet caching code in Etomite code - bugs are documented in the Tracker

#3 traderhut

traderhut

    Etomite Forum Newbie

  • Member
  • 18 posts

Posted 06 September 2010 - 12:08 AM

I too was wanting to do this same thing...

Sounds like another tab, 'Library' would be good... Like chunks, but of importable PHP code... I was originally thinking a chunk would work, and just put the php code in there, but that won't work.

I'm looking to put a lookup routine in place that would be called from several locations... I can copy the code from one snippit to another, but yuck...

I guess I could execute the code as a snippit...

There seems to be a lot of unfinished things in the code... :-( There is for example a tab (roles) that is always blank... Has been there for years (since last time I used the software), but who knows, maybe someday it will get filled in... Or maybe I just don't know what I'm doing there...

Anyway, I guess I'm going to go with the cut and paste solution for now...

-Chert

-- www.runecube.com - the etomite site I"m working on...

#4 traderhut

traderhut

    Etomite Forum Newbie

  • Member
  • 18 posts

Posted 06 September 2010 - 06:39 AM

Oops, the tab should have been 'Permissions' not Roles.. I can define a role, just never set permissions for a folder (or page?)

-Chert

-- www.runecube.com - the etomite site I"m working on...

#5 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 06 September 2010 - 01:58 PM

There is a patch for the permissions tab issue here in these forums...

#6 Cris D.

Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts

Posted 10 September 2010 - 12:40 PM

And you can add embedded php code in a chunk instead of using $etomite->runSnippet() by enabling the "allow embedded php" in the Etomite configuration. This is probably more intuative method for those used to pure php and want to bypass the runSnippet caching bugs.

#7 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 10 September 2010 - 09:13 PM

And you can add embedded php code in a chunk instead of using $etomite->runSnippet() by enabling the "allow embedded php" in the Etomite configuration. This is probably more intuative method for those used to pure php and want to bypass the runSnippet caching bugs.


This will also allow PHP to be used in page templates as well...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users