Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xss filter avoidance #517

Open
tablatronix opened this issue Feb 11, 2013 · 2 comments
Open

xss filter avoidance #517

tablatronix opened this issue Feb 11, 2013 · 2 comments

Comments

@tablatronix
Copy link
Member

When using the code editors I typically experience xss filters that prevent me from submitting. These are either browser reflected xss filters or apache mod_sec.

Avoiding these can be done via ajax submission, but even better would be to encode our form data when submitting to the server.

@tablatronix
Copy link
Member Author

Some workarounds are to disable mod_sec for some stuff. Which is risky, we do use a nonce so that helps a little.

if your host allows it via .htaccess

# disables mod_sec for specific ip and post only
SetEnvIf Remote_Addr ^xxx\.xxx\.xxx\.xxx$ MODSEC_ENABLE=Off
SetEnvIf Request_Method !^POST$ MODSEC_ENABLE=On

You can also disable specific mod_sec rules if you can identify them, or specify specific pages and forms.

@tablatronix
Copy link
Member Author

Did a quick and dirty test encoder that can be done with a plugin via hooks.
Obviously needs testing and has no base64 fallback for browsers that do not support btoa
no clue what the char support is for unicode etc. but you get the gist, could always do some serializing or a custom encoder $val.serialize() etc.

// common hook
if (get_filename_id() == 'components' && isset($_POST['submitted'])){
    if(isset($_POST['encoded'])){
        foreach($_POST['val'] as $key=>&$val){
            $val = base64_decode($val);
            // print_r("DECODING DATA for $key \n");
            // print_r($val);
        }
        unset($val);
    }

    // echo "<pre>";
        // var_dump($_POST);
    // echo "</pre>";
    // die();
}   
// use php or js to target which pages, depending on which hooks and where you output 
// <?php if (get_filename_id() == 'components'){ /?>
<script>
$( document ).ready(function(){
    $("#components form.manyinputs").submit(function(e){
        e.preventDefault();
        var form = this;
        $(form).find($("textarea[name='val[]']")).each(function(e){
            $newval = btoa($(this).val());
            // console.log($newval);
            $(this).val($newval);
        });
        $("form.manyinputs").append($("<input name=encoded value=true>"));
        form.submit(); // submit bypassing the jQuery bound event
    });
});
</script>
// <?php } ?>

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

No branches or pull requests

1 participant