S9 TextFormatter PHP Injection via phpBB not working

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
friedfry
Registered User
Posts: 6
Joined: Sun Nov 04, 2018 6:54 pm

S9 TextFormatter PHP Injection via phpBB not working

Post by friedfry »

Hey guys,
I'm having problems even with the simple PHP injection via phpBB tutorial now. It throws an error that the argument passed to my listener function is from the object "\s9e\TextFormatter\Parser\Tag", but "phpbb\\event\\data" and the site is obviously not rendering. If I remove the boundry that the parameter needs to be an object from the type "\s9e\TextFormatter\Parser\Tag", it doesn't find the method setAttribute.
I'm using phpBB 3.2.2

Code: Select all

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to illumina\\chemtags\\event\\main_listener::chemtag_filter() must be an instance of s9e\\TextFormatter\\Parser\\Tag, instance of phpbb\\event\\data given

Code: Select all

<?php

namespace illumina\chemtags\event;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use s9e\TextFormatter\Parser;

class main_listener implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return array(
            'core.text_formatter_s9e_configure_after' => 'chemtag_filter'
        );
    }
    public function configure_chemtag($event)
    {
        $event['configurator']->tags['QUOTE']->filterChain->append(array(__CLASS__, 'chemtag_filter'));
    }


    static public function chemtag_filter(\s9e\TextFormatter\Parser\Tag $tag)
    {
        $tag->setAttribute('author', 'Mark Twain');
        // We return TRUE to indicate that the tag is allowed
        return true;
    }
}
?>
Thanks for helping and have a nice weekend!
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: S9 TextFormatter PHP Injection via phpBB not working

Post by kasimi »

Your event listener is chemtag_filter but it should be configure_chemtag:

Code: Select all

'core.text_formatter_s9e_configure_after' => 'cconfigure_chemtag'
friedfry
Registered User
Posts: 6
Joined: Sun Nov 04, 2018 6:54 pm

Re: S9 TextFormatter PHP Injection via phpBB not working

Post by friedfry »

Ok, yeah thanks, thats embarrasing. Not sure how long that error stood in there, I was trying quite a few of variants.
Having corrected that and fiddeling around a bit more, the example is now working just fine. I noticed that for more or less defined behaviour you have to clear the cache, or post a new reply/thread to load that function and not just reload the page with the content.
Another trouble I'm having now is making a custom BBcode/tag according to this tutorial.
Inside my configure function I'm adding a BBCode with following code:

Code: Select all

 $configurator = new Configurator;
$configurator->BBCodes->addCustom('[try string={TEXT}]', '{@string} is a test');
and with this one, I'm trying to add it to the filter chain, so it would call my filter function like above.

Code: Select all

$event['configurator']->tags['try']->filterChain->append(array(__CLASS__, 'chemtag_filter'));
But now at throws an error, that the tag "try" is not found. I'm not sure why, because it follows the same principle as in the tutorial. The tagname try should be extracted from the added custom bbcode, if I understood right. I also tried adding it directly to the configurator variable with the following:

Code: Select all

$configurator->tags['try']->filterChain[] = 'chemtag_filter';
The complete error:

Code: Select all

PHP Fatal error:  Uncaught RuntimeException: Tag 'try' does not exist in /srv/http/illumina-phpbb3/vendor/s9e/text-formatter/src/Configurator.php:8238\nStack trace:\n#0 /srv/http/illumina-phpbb3/vendor/s9e/text-formatter/src/Configurator.php(7363): s9e\\TextFormatter\\Configurator\\Collections\\TagCollection->getNotExistException('try')\n#1 /srv/http/illumina-phpbb3/vendor/s9e/text-formatter/src/Configurator.php(7383): s9e\\TextFormatter\\Configurator\\Collections\\NormalizedCollection->get('try')\n#2 /srv/http/illumina-phpbb3/ext/illumina/chemtags/event/main_listener.php(28): s9e\\TextFormatter\\Configurator\\Collections\\NormalizedCollection->offsetGet('try')\n#3 [internal function]: illumina\\chemtags\\event\\main_listener->configure_chemtag(Object(phpbb\\event\\data), 'core.text_forma...', Object(phpbb\\event\\dispatcher))\n#4 /srv/http/illumina-phpbb3/vendor/symfony/event-dispatcher/EventDispatcher.php(184): call_user_func(Array, Object(phpbb\\event\\data), 'core.text_forma...', Object(phpbb\\event\\dispatcher))\n#5 /srv/http/illumina-phpbb3/vendor/sy in /srv/http/illumina-phpbb3/vendor/s9e/text-formatter/src/Configurator.php on line 8238, referer: http://127.0.0.1/illumina-phpbb3/posting.php?f=54&mode=soft_delete&p=70744&confirm_key=1O34I9V55P
I really don't get how I can't get any progress at all on my own. I again tried a few hours to get it working, read all the different tutorials, but it just throws one error after fixing the other. I seem to lack in understanding the principles of the whole system I think... Anyway, I really appreciate your help!
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: S9 TextFormatter PHP Injection via phpBB not working

Post by kasimi »

Instead of creating a new configurator, did you try using the configurator provided in the event data?

Code: Select all

$event['configurator']->BBCodes->addCustom('[try string={TEXT}]', '{@string} is a test');
Post Reply

Return to “Extension Writers Discussion”