Passing PHP filtered arguments to Panel and View Pane
By far the best way to do this is to provide your own context.

See What are Ctools plugin (content type, access, etc), and how does one create them? for how ctools plugins work, and adapt one of the examples to a context plugin instead.

That way you can decide what data is passed into Panels, and on to the individual panes in a safe manner.