views:

210

answers:

0

I'm adding some capabilities to an api to allow third parties to store user data. I know some users may already base64 encode their user ids before submitting them through the api, others might not.

I've done some checking on double encoding (encoding base64 of an already base64 encoded string), and it doesn't SEEM to be causing any problems.

From my understanding, it isn't possible to check if a string is base64 encoded. Is there something here I should be looking out for down the line? is there another way I should be doing this, or is it safe?

Also, i'm cleaning the data like this.

$eid=preg_replace("/[^a-zA-Z0-9\/=+]/", "",base64_encode(@$_GET['eid']));

that should be safe to store in the database as it strips out any suspect characters after the string is encoded. But I'll need to return the non-encoded string to through the API.

So at some point I'll need to do

echo base64_decode($eid);
And it seems to me that this could be an opportunity for a hacker to run malicious code through my server. Is that right?