Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:29:15+00:00 2026-06-01T23:29:15+00:00

I’ve recently edited some regexps on a phpbb2’s bbcode.php and I’m wondering if it’d

  • 0

I’ve recently edited some regexps on a phpbb2’s bbcode.php and I’m wondering if it’d bring security issues (regarding script injection from href, mainly (if it’s even possible)).

I edited only the [url], [url=] and my newly created [url=””] bbcode tags.

Their original regexps (dated to 2008) didn’t allow “invalid” characters such as parentheses or white spaces in the url value (which are needed for some Wikipedia pages and file hosting services’ URLs), so instead of encoding the URLs’ special characters as suggested by others, I just edited the regex to allow alphanumeric characters in the protocols and basically any character in the domain/rest of the url address.

The new regexps inside phpbb2’s bbencode_second_pass function ($text = post’s text):

// matches a [url]xxxx://www.phpbb.com[/url] code..
$patterns[] = "#\[url\]([\w]+?://.*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url1'];

// [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
$patterns[] = "#\[url\]((www|ftp)\..*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url2'];

// [url=xxxx://www.phpbb.com]phpBB[/url] code..
$patterns[] = "#\[url=([\w]+?://.*?)\]([^?\n\r\t].*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url3'];

// [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
$patterns[] = "#\[url=((www|ftp)\..*?)\]([^?\n\r\t].*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url4'];


// [url="xxxx://www.phpbb.com"]phpBB[/url] code..
$patterns[] = "#\[url="([\w]+?://.*?)"\]([^?\n\r\t].*?)\[/url\]#is"; //closes on first "]
//$patterns[] = "#\[url="([\w]+?://.*?)"\](?![\w\n\s]*"\])([^?\n\r\t].*?)\[/url\]#is"; //closes on last "] //discarded, ambigous
$replacements[] = $bbcode_tpl['url3'];

// [url="www.phpbb.com"]phpBB[/url] code.. (no xxxx:// prefix).
$patterns[] = "#\[url="((www|ftp)\..*?)"\]([^?\n\r\t].*?)\[/url\]#is";
$replacements[] = $bbcode_tpl['url4'];


// [email]user@domain.tld[/email] code..
$patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si";
$replacements[] = $bbcode_tpl['email'];


$text = preg_replace($patterns, $replacements, $text);

// Remove our padding from the string..
$text = substr($text, 1);

return $text;

And the unedited phpbb2 declarations:

$bbcode_tpl['url1'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url1'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url1']);

$bbcode_tpl['url2'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
$bbcode_tpl['url2'] = str_replace('{DESCRIPTION}', '\\1', $bbcode_tpl['url2']);

$bbcode_tpl['url3'] = str_replace('{URL}', '\\1', $bbcode_tpl['url']);
$bbcode_tpl['url3'] = str_replace('{DESCRIPTION}', '\\2', $bbcode_tpl['url3']);

$bbcode_tpl['url4'] = str_replace('{URL}', 'http://\\1', $bbcode_tpl['url']);
$bbcode_tpl['url4'] = str_replace('{DESCRIPTION}', '\\3', $bbcode_tpl['url4']); 

This works perfectly fine with my debugging so far, now I’d like to ask if, by allowing any character to be placed inside the A tag’s href attribute I’d exposing my users or myself to any hacker attack?

Say, I tested the javascript URI hack (javascript:) and it doesn’t seem to work even on Internet Explorer, and I don’t know of any way of injecting a script through the href attribute of an A tag, would there be any risk in allowing my users to type whatever they like (as long as there’s either a valid alphanumeric protocol such as *:// or www. which will have a http:// placed prior to it) in the href of tags?

Please note that I’m not considering linking to malicious sites, I want to know if hackers would be able to inject scripts/cookies/whatever through the href of an tag without the user clicking on it!

Now it sounds a little redundant to have a href attribute run anything without its tag being clicked, but anyway, is there a way for a hacker to inject malicious code/javascript in the document through the href attribute?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:29:17+00:00Added an answer on June 1, 2026 at 11:29 pm

    I haven’t tested it myself, but the following might still work:

    [url]javascript://%0Aalert(1)[/url]
    [url=javascript://%0Aalert(1)]…[/url]
    [url="javascript://%0Aalert(1)"]…[/url]
    

    These should all result in the following JavaScript code as %0A is decoded to a newline character:

    //
    alert(1)
    

    Next guess: As you’re allowing any character, including the attribute value delimiting ", these might work:

    [url]http://example.com/" onclick="alert(1)[/url]
    [url=http://example.com/" onclick="alert(1)]…[/url]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.