# Stripping Outlook Safe Link URLs?

**URL:** <https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114>\
**Category:** Feature\
**Tags:** email\
**Created:** [March 14, 2023, 2:02pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114 "2023-03-14T14:02:47Z")\
**Posts on this page:** 11\
**Page:** 1

## AI-generated summary

In a discussion titled "Stripping Outlook Safe Link URLs?" under the Feature category and tagged with "email," [ethang](/t/-/258114/1) reports that Outlook’s Safe Links feature wraps URLs in obfuscated Microsoft URLs when forwarding emails to Discourse, breaking link previews and creating messy links. [pfaffman](/t/-/258114/2) initially suggests users avoid email forwarding and use Discourse directly, but later acknowledges the problem may be solvable. [supermathie](/t/-/258114/6) investigates and confirms the URLs follow a predictable pattern, offering a Python snippet to extract the original URL from `nam*.safelinks.protection.outlook.com` links. [ethang](/t/-/258114/7) provides an example showing account-specific metadata in the URL, which [supermathie](/t/-/258114/8) notes is irrelevant for unwrapping. [supermathie](/t/-/258114/9) tests whether Safe Links break oneboxing and finds some sites still preview correctly, though the URLs remain visually ugly. [ethang](/t/-/258114/10) agrees the visual clutter is the main issue. [pfaffman](/t/-/258114/11) and [supermathie](/t/-/258114/12) note similar frustrations with Outlook’s link rewriting. [supermathie](/t/-/258114/13) proposes a balanced solution: preserve the Safe Link as the target URL for security, but display the clean, unwrapped URL as the visible text — allowing users to benefit from Microsoft’s safety features while maintaining readability in Discourse. The community is invited to weigh in on whether stripping Safe Links compromises security intent or improves user experience.

<div class="post-metadata">

**Author:** ![ethang](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethang/32/297870_2.png) [@ethang](https://meta.discourse.org/u/ethang)\
**Post date:** [March 14, 2023, 2:02pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/1 "2023-03-14T14:02:47Z")

</div>

Good morning - I’m an admin on a hosted (Business tier) forum for a software service, and I am trying to gently encourage more of our users to post to our Discourse rather than emailing me directly by forwarding messages to create new topics.

Unfortunately, my email is a managed Outlook/Office 365 account with [Safe Links](https://learn.microsoft.com/en-us/microsoft-365/security/office-365-security/safe-links-about?view=o365-worldwide) enabled in Windows Defender, and I have no control over the policies, so when enabling posting-by-email in Discourse and forwarding any messages from my email account, any links contained in the message come out an awful sight in the resulting Discourse topic, wrapped in one of Microsoft’s obfuscated Safe Link URLs (and breaking Discourse’s link previews, etc)

Is there any tool/option on the Discourse side to strip a posted Office365 Safe Link URL back down to the original link? An email setting I am missing or a plugin that could be used to set such a posting policy? I suspect this is just something I’ll have to fix manually when forwarding messages on the Outlook side, but thought it was worth asking.

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [March 14, 2023, 2:17pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/2 "2023-03-14T14:17:33Z")

</div>

> [@ethang](#):
>
> I am trying to gently encourage more of our users to post to our Discourse rather than emailing me directly by forwarding messages to create new topics.

Since Outlook rewrites URLs, you’ll need to gently encourage them to use Discourse by using Discourse yourself. 🙂

> [@ethang](#):
>
> Is there any tool/option on the Discourse side to strip a posted Office365 Safe Link URL back down to the original link?

Discourse will in many cases follow redirects to get to the URL to produce a onebox, but if that’s not working then I’m afraid that you’ll need to use the Discourse UX rather than you email client to create the topics.

---

<div class="post-metadata">

**Author:** ![ethang](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethang/32/297870_2.png) [@ethang](https://meta.discourse.org/u/ethang)\
**Post date:** [March 14, 2023, 2:48pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/4 "2023-03-14T14:48:43Z")

</div>

> [@pfaffman](#):
>
> Since Outlook rewrites URLs, you’ll need to gently encourage them to use Discourse by using Discourse yourself. 🙂

…I do? But since there is a post-via-email feature, that would imply that there are times where it is convenient to do so 🙂 like, say, hitting “forward” on an existing message rather than having to manually copy-paste between UIs

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [March 14, 2023, 4:28pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/6 "2023-03-14T16:28:41Z")

</div>

> Safe Links scans incoming email for known malicious hyperlinks. Scanned URLs are rewritten or _wrapped_ using the Microsoft standard URL prefix: `https://nam01.safelinks.protection.outlook.com` .

We might be able to unwrap these, can you post some examples of _how_ they’re rewritten?

Trawling my inbox I have two:

```plaintext
https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fvcacanada.com%2F&data=02%7C01%7Cinternalmedicine.altavista%40vca.com%7C8b234337846c4b26704608d859d038fb%7Ca2bdfa5ebe874736892b6db8bbf91546%7C1%7C0%7C637358098123527523&sdata=2b8GyZaj5cH3XNVMQ7KuIB8zgv2n4rEqX2MJutsQn2c%3D&reserved=0
https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fembed%2F4qo27xcVS5I&data=02%7C01%7C%7C53e03ffe911442ddf50108d6492424d0%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636776816911303670&sdata=vzPKnv1BDVf6LL4z9P3faVYkxxcLcyjnnrLcch%2B1npA%3D&reserved=0

```

This does look pretty easy:

```python
def un_safelink(link):
    try:
        parsed = urllib.parse.urlparse(link)
        if parsed.netloc != 'nam01.safelinks.protection.outlook.com':
            return link
        query = urllib.parse.parse_qs(parsed.query)
        return query['url'][0]
    except:
        return link

```

---

<div class="post-metadata">

**Author:** ![ethang](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethang/32/297870_2.png) [@ethang](https://meta.discourse.org/u/ethang)\
**Post date:** [March 14, 2023, 4:37pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/7 "2023-03-14T16:37:37Z")

</div>

I think they all follow a similar pattern, although looks like in my case there’s also some kind of reference to my particular account, which is probably an enterprise-level subscription thing, e.g.:

```plaintext
https://nam12.safelinks.protection.outlook.com/?url=http%3A%2F%2Ftransformativemedia.swinburne.edu.au%2F&data=05%7C01%7Cethan.gates%40yale.edu%7Cd0c6ce8e6b4c44f1d9f508db243eda00%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C638143624621704534%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=B5zPUFQ4qRQqSdmtimFQLCnosghaZENDmyaz2zZlw40%3D&reserved=0

```

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [March 14, 2023, 4:42pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/8 "2023-03-14T16:42:42Z")

</div>

> [@supermathie](#):
>
> the Microsoft standard URL prefix: `https://nam01.safelinks.protection.outlook.com`

> [@ethang](#):
>
> `https://nam12.safelinks.protection.outlook.com`

🤨

so much for documentation

> [@ethang](#):
>
> reference to my particular account

Yes, looks like it encodes the email address of the sender or receiver into the metadata. Not that we need it:

```plaintext
{'url': ['http://transformativemedia.swinburne.edu.au/'],
 'data': ['05|01|frodo.baggins@yale.edu|d0c6ce8e6b4c44f1d9f508db243eda00|dd8cbebb21394df8b4114e3e87abeb5c|0|0|638143624621704534|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0=|3000|||'],
 'sdata': ['B5zPUFQ4qRQqSdmtimFQLCnosghaZENDmyaz2zZlw40='],
 'reserved': ['0']}

```

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [March 14, 2023, 4:45pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/9 "2023-03-14T16:45:47Z")

</div>

> [@ethang](#):
>
> breaking Discourse’s link previews

… I don’t think it does?

[https://nam12.safelinks.protection.outlook.com/?url=http%3A%2F%2Ftransformativemedia.swinburne.edu.au%2F&data=05|01|ethan.gates%40yale.edu|d0c6ce8e6b4c44f1d9f508db243eda00|dd8cbebb21394df8b4114e3e87abeb5c|0|0|638143624621704534|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|3000|||&sdata=B5zPUFQ4qRQqSdmtimFQLCnosghaZENDmyaz2zZlw40%3D&reserved=0](https://nam12.safelinks.protection.outlook.com/?url=http%3A%2F%2Ftransformativemedia.swinburne.edu.au%2F&data=05%7C01%7Cethan.gates%40yale.edu%7Cd0c6ce8e6b4c44f1d9f508db243eda00%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C638143624621704534%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=B5zPUFQ4qRQqSdmtimFQLCnosghaZENDmyaz2zZlw40%3D&reserved=0)

Ah, that’s ugly. I saw in preview:

> ![image](https://global.discourse-cdn.com/meta/original/4X/8/d/4/8d45f7f825964ccdf5f7467f2a7977a4c3c400bd.png)

It should behave the same as:

[https://transformativemedia.swinburne.edu.au](https://transformativemedia.swinburne.edu.au)

Though a site that oneboxes still works:

> **[Animal Hospitals, Veterinarians & Emergency Vets | VCA Canada](https://vcacanada.com/)**
>
> We see things differently at VCA Canada. We don’t see an animal, we see a family member. We don’t see an annual exam, but a wellness consultation that will contribute to a happy, healthy pet for life.

This might just be a matter of tweaking how we generate “inline titles” for these links.

---

<div class="post-metadata">

**Author:** ![ethang](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethang/32/297870_2.png) [@ethang](https://meta.discourse.org/u/ethang)\
**Post date:** [March 14, 2023, 4:56pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/10 "2023-03-14T16:56:41Z")

</div>

ah that may have just been a bad example re: the previews/oneboxing, I will try out some other examples. That’s less of a concern than the unwieldy links/URLs themselves, in any case!

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [March 14, 2023, 4:57pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/11 "2023-03-14T16:57:18Z")

</div>

> [@ethang](#):
>
> I do?

It depends on how “safe” Microsoft has made the urls. Seems like it might be possible to make them work,though, so it seems I was too pessimistic about how hard the problem is. Sorry about that.

I’ve had several exchanges of email with someone using Microsoft that made it hard to read them in my own mail reader.

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [March 14, 2023, 4:57pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/12 "2023-03-14T16:57:50Z")

</div>

> [@pfaffman](#):
>
> I’ve had several exchanges of email with someone using Microsoft that made it hard to read them in my own mail reader.

Examples welcome, eh!

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [March 14, 2023, 5:05pm UTC](https://meta.discourse.org/t/stripping-outlook-safe-link-urls/258114/13 "2023-03-14T17:05:47Z")

</div>

I would be curious to get input from other business-type users as to whether stripping this entirely violated their security intent. One of the benefits of this feature is a URL can later be deemed “unsafe” and further attempts to click it will be blocked.

On the other hand, forum owners might be grumpy that Microsoft is “tracking all of their forum users activity”.

I can see two sides to an argument here.

A decent approach to take might be:

- if a safelinked URL is pasted (on its own or inline)
  - resolve the onebox normally
  - if no onebox or title, make the “pretty text” the unwrapped link
  - the link target should still be the safelinked URL

i.e. it would look like:

[https://transformativemedia.swinburne.edu.au](https://nam12.safelinks.protection.outlook.com/?url=http%3A%2F%2Ftransformativemedia.swinburne.edu.au%2F&data=05%7C01%7Cethan.gates%40yale.edu%7Cd0c6ce8e6b4c44f1d9f508db243eda00%7Cdd8cbebb21394df8b4114e3e87abeb5c%7C0%7C0%7C638143624621704534%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=B5zPUFQ4qRQqSdmtimFQLCnosghaZENDmyaz2zZlw40%3D&reserved=0)
