# Bidirectional characters in LTR languages post security fix

**URL:** https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819
**Category:** Support
**Created:** [November 22, 2021, 7:33am UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819 "2021-11-22T07:33:37Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![yaron](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yaron/32/119812_2.png) [@yaron](https://meta.discourse.org/u/yaron)
#### Post date: [November 22, 2021, 7:33am UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/1 "2021-11-22T07:33:37Z")

</div>

I just ran into the following PR:  
[https://github.com/discourse/discourse/pull/15032](https://github.com/discourse/discourse/pull/15032)

I think it my render legit Hebrew or Arabic text unreadable.

One of the solutions I ran into was disabling the unicode algorithms and just display some representation of non-printable characters (I think it was implemented in Pootle).  
So basically the idea is to turn:  
This‎‏ text

Into:  
This\<LRM\>\<RLM\> text

This way to user can choose if this is malicious or not by understanding what the actual characters are and possibly choose to enable the unicode algorithms to be able to read the text properly.  
Thanks.

---

<div class="post-metadata">

### Author: ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)
#### Post date: [November 22, 2021, 10:30pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/3 "2021-11-22T22:30:32Z")

</div>

Thank you for raising this, we did think of this concern. The fix you linked in the OP only applies to unicode bidirectional characters in `pre` and `code` blocks, either manually written as HTML or generated from ````` markdown fenced code blocks, so it should not be an issue with regular Hebrew or Arabic text in a composed post.

---

<div class="post-metadata">

### Author: ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)
#### Post date: [November 22, 2021, 10:30pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/4 "2021-11-22T22:30:37Z")

</div>



---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 22, 2021, 10:36pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/5 "2021-11-22T22:36:15Z")

</div>



---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 22, 2021, 10:42pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/7 "2021-11-22T22:42:22Z")

</div>

Demo:

```plaintext
#include <cstdio.h>

int main() {
    /* Say hello; newline*/ return 0 ;
    printf("Hello world.\n");
    return 0;
}

```

```
#include 

int main() {
    /* Say hello; newline*/ return 0 ;
    printf("Hello world.\n");
    return 0;
}
```

Test: “שלום חבר” - Hello Friend

Without BIDI

Test: “שלום חבר” - Hello Friend

Markdown:

```plaintext
Test: "שלום חבר" - Hello Friend

Without BIDI

Test: "שלום חבר" - Hello Friend

```

Not the best example in the world, but you should get the gist here, only impacts source code being posted on the forum. Bidi chars in source code is not something that is usually done.

---

<div class="post-metadata">

### Author: ![yaron](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yaron/32/119812_2.png) [@yaron](https://meta.discourse.org/u/yaron)
#### Post date: [November 23, 2021, 3:21pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/8 "2021-11-23T15:21:49Z")

</div>

I’ll give another example where no RLM does break the sentence.

שלום לכולם ובמיוחד ל־Sam, Martin בחר לעזוב אותנו.

שלום לכולם ובמיוחד ל־Sam,‏ Martin בחר לעזוב אותנו.

Do you see the difference?  
The only change there is RLM, I wanted to congratulate Sam and inform that Martin is leaving (No offense).

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 23, 2021, 8:16pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/9 "2021-11-23T20:16:44Z")

</div>

Yes, that example is certainly much better! As you can see it continues to work and is not impacted by the security fix 🎉

---

<div class="post-metadata">

### Author: ![yaron](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yaron/32/119812_2.png) [@yaron](https://meta.discourse.org/u/yaron)
#### Post date: [November 24, 2021, 1:27pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/10 "2021-11-24T13:27:07Z")

</div>

Hmmm it’s not a codeblock 🙂  
I meant that inside a codeblock it won’t appear as expected (This is what the fix is all about, am I right?)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 24, 2021, 9:39pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/11 "2021-11-24T21:39:18Z")

</div>

> [@yaron](#):
>
> I meant that inside a codeblock it won’t appear as expected

Yeah but why would you include it in a code block?

---

<div class="post-metadata">

### Author: ![yaron](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yaron/32/119812_2.png) [@yaron](https://meta.discourse.org/u/yaron)
#### Post date: [November 24, 2021, 9:56pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/12 "2021-11-24T21:56:54Z")

</div>

Excerpt from gettext, Hebrew/Arabic native strings, there are such cases.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 25, 2021, 1:47am UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/13 "2021-11-25T01:47:22Z")

</div>

> [@yaron](#):
>
> Excerpt from gettext,

I would the outlier case here has workarounds (screenshot, attachment uploads and so on), also it is pretty clear that the special char is in place.

The risk of [https://trojansource.codes/](https://trojansource.codes/) is higher than the risk of mild disruption in extreme outlier cases.

---

<div class="post-metadata">

### Author: ![yaron](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yaron/32/119812_2.png) [@yaron](https://meta.discourse.org/u/yaron)
#### Post date: [November 25, 2021, 5:47am UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/14 "2021-11-25T05:47:07Z")

</div>

But my suggestion breaks the sentence with some cue, so replacing the RLM and LRM with \<RLM\> or \<LRM\> will show the user that there were some additional characters and now the text is rendered without them yet informing that it might break the experience and that there’s an option to replace back manually if needed, removing the characters completely without some indicators gives no room for educated decisions.

And it will also prevent trojan source code as you mentioned because the user will be able to see the malicious code with the indicators.

I will try to get some screenshots from Pootle, I don’t remember seeing that raw strings option in the past couple of years, it was very useful when we started fixing the LibreOffice localization.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 25, 2021, 6:10am UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/15 "2021-11-25T06:10:45Z")

</div>

Not following, we do not strip we replace , see my example above

---

<div class="post-metadata">

### Author: ![yaron](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yaron/32/119812_2.png) [@yaron](https://meta.discourse.org/u/yaron)
#### Post date: [November 28, 2021, 4:04pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/16 "2021-11-28T16:04:28Z")

</div>

I understand, wouldn’t it be better to use their names instead of Unicode entity?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 28, 2021, 9:05pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/17 "2021-11-28T21:05:07Z")

</div>

If there is repeat confusion reported in the wild we can certainly fine tune

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 28, 2021, 9:05pm UTC](https://meta.discourse.org/t/bidirectional-characters-in-ltr-languages-post-security-fix/209819/18 "2021-12-28T21:05:19Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
