Using HTML inside lang files

Post

Posted
Rating:
#3844 (In Topic #754)
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’

Something REALLY odd happening

I don't know what's happening – whatever it is it seems to be intermittent.

I've got some custom lang files containing strings that define URLs and text formatting using HTML. When referencing the lang file and string in a Comcode page, sometimes the HTML is shown as text and other times it parses accurately.

I thought there was something wrong with my custom lang file, so I tried to reproduce the error with global.ini.

{!TUTORIAL_ON_THIS} has got some HTML in it, and when referenced on a Comcode page, the same result is given – sometimes it parses the HTML and sometimes it doesn't.

When it seems to work, I'll remove {!TUTORIAL_ON_THIS}, save the page, then edit and put it back on, and it displays as text again.

I also tried creating a test page that only contained a referenced language string, and same results occurred – so it doesn't have anything to do with interference with other content on the page.

I also thought maybe I was missing some HTML or forgot to close a tag in my themes template files causing errors but the standards checker doesn't show any major errors or missing tags so that shouldn't have any impact on this issue.

I'm out of ideas. Composr is trying to make me look crazy  O_o

Edit: tried using a different browser too. I did a recent update on Firefox but Chrome and IE are both doing it as well, so it's not browser specific.
Online now: No Back to the top

Post

Posted
Rating:
#3855
Avatar
Site staff
Adam Edington is in the usergroup ‘Super-moderators’
I am no expert, but maybe try There is a tutorial which covers this feature.

*shrugs*
Online now: No Back to the top

Post

Posted
Rating:
#3856
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’
Thanks KingBast.

I think, but not sure, that using an asterisk just strips any formatting, including HTML. So it would just render as text anyway.

I'll give it a try later though. I'm not near my computer atm.
Online now: No Back to the top

Post

Posted
Rating:
#3857
Avatar
Site staff
Adam Edington is in the usergroup ‘Super-moderators’

Composr Tutorial: Tempcode programming - Composr said

Escaping

Any of the above 4 Tempcode constructs may be escaped. By "escaped", I mean made to fit in an encoding scheme, such as HTML or URLs, such that special text characters do not interact with that encoding scheme in an insecure/corrupting way). This is done with ease using escaping filters, just by placing the character associated with the mode of escaping before the closing '}'. For example, {BLAH*} will add the parameter BLAH, escaped for HTML output.

Not sure, but I'm not reading anything about stripping the HTML there. Worth a try :)
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Adam Edington)
#3861
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
I suspect if you remove this line from sources/global3.php it will remove the auto-escaping behaviour:

Code

$ESCAPE_HTML_OUTPUT[$ret] = true;

Composr will automatically escape stuff if custom PHP files are present and no declaration is in those custom files that the programmer understands how to avoid XSS vulnerabilities. I don't think it is supposed to affect language strings inside a Comcode page though.
I'll try and reproduce and resolve this properly, but it might be quite hard for me to do so.
If you can provide me access to test on your site that might help (including being able to save code changes, e.g. FTP). Or a backup of your site I can test with.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Adam Edington)
#3866
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’

KingBast said

Composr Tutorial: Tempcode programming - Composr said

Escaping

Any of the above 4 Tempcode constructs may be escaped. By "escaped", I mean made to fit in an encoding scheme, such as HTML or URLs, such that special text characters do not interact with that encoding scheme in an insecure/corrupting way). This is done with ease using escaping filters, just by placing the character associated with the mode of escaping before the closing '}'. For example, {BLAH*} will add the parameter BLAH, escaped for HTML output.

Not sure, but I'm not reading anything about stripping the HTML there. Worth a try :)

Thanks KingBast, you're right, and now it is working properly. I guess I misunderstood the use of asterisks.

It's just funny how it was intermittent, and in other areas of my site I reference custom lang strings with HTML and they seem to work fine without the need to use an asterisk.

Oh well, thanks again for the replies.
Online now: No Back to the top

Post

Posted
Rating:
#3873
Avatar
Site staff
Adam Edington is in the usergroup ‘Super-moderators’
I certainly wasn't talking from experience of having the same issue and solving it this way, but glad it worked out :)
Online now: No Back to the top

Post

Posted
Rating:
#3899
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
I tried but was not able to reproduce this. It would likely depend on exactly what code files were overridden in a Composr installation, or how custom blocks may be included.
If some code file where the declarations are managed is overridden that may confuse the system for example and it might not be able to properly trace whether it should or shouldn't be doing the automatic escaping for the part of the system running – but I'm just guessing.

I appreciate how it would be very confusing. At the same time, the vast majority of programmers writing custom code have no idea how to avoid making XSS vulnerabilities and will make their site wide open to them, hence wide open to being completely hacked. Hence the automatic escaping on custom code if no declaration of understand them is made. Of course ideally it wouldn't behaviour unexpectedly like it is here. XSS is a huge problem on websites and probably the majority of websites actually have multiple XSS security holes.

From the next patch release the automatic escaping will be disableable with this Commandr command:

Code

:set_value('kid_gloves_html','0');

I highly advise anyone doing any custom programming, especially outputting URL parameters into pages, to think carefully about XSS. Simply doing doing some Tempcode like this would open an XSS hole (and actually I checked and our filter can't actually protect against it unfortunately):

Code

{$_GET,test}
This is because a hacker can do a URL like:

Code

...&test=<script>window.alert('!');</script>
and it would run on whoever's machine clicked that link. Obviously more malicious JS would be used than that.

So anyway, we'll provide an official way to disable our XSS escaping as above, but I encourage people to think about the issue.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#3903
Joe
Avatar
Standard member
Joe is in the usergroup ‘Honoured member’
So Chris, by adding an asterisk inside the tempcode, you said this makes it safer? Like using {$_GET*} Instead of {$_GET}?
Online now: No Back to the top

Post

Posted
Rating:
#3904
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
Yes.

You need to think about it as translation between formats.

$_GET will get it as raw plain text.

But you're putting it into HTML.

HTML is not plain text. It interprets code, such as HTML tags.

So you need to 'escape' it to make it embed within the HTML as text.

It does stuff like change < to &lt.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top
1 guest and 0 members have just viewed this.

Statistics

Forum statistics:
  • 2,052 topics, 7,195 posts, 10,831 members
  • Our newest member is kritika12
Birthdays:
Back to Top