Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 41 additions & 37 deletions .github/templates/README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Check out the official [Documentation](https://codeshelldev.github.io/secured-si
- [Configuration](#configuration)
- [Endpoints](#endpoints)
- [Variables](#variables)
- [Data Aliases](#data-aliases)
- [Field Mappings](#field-mappings)
- [Message Templates](#message-templates)
- [Integrations](https://codeshelldev.github.io/secured-signal-api/docs/integrations/compatibility)
- [Contributing](#contributing)
Expand Down Expand Up @@ -229,25 +229,26 @@ These Endpoints are blocked by default due to Security Risks.
> [!NOTE]
> Matching works by checking if the requested Endpoints starts with a Blocked or an Allowed Endpoint

You can modify Blocked Endpoints by configuring `blockedEndpoints` in your config:
You can modify endpoints by configuring `access.endpoints` in your config:

```yaml
settings:
blockedEndpoints: [/v1/register, /v1/unregister, /v1/qrcodelink, /v1/contacts]
access:
endpoints:
- !/v1/register
- !/v1/unregister
- !/v1/qrcodelink
- !/v1/contacts
- /v2/send
```

You can also override Blocked Endpoints by adding Allowed Endpoints to `allowedEndpoints`.
By default adding an endpoint explictly allows access to it, use `!` to block it instead.

```yaml
settings:
allowedEndpoints: [/v2/send]
```

| Config (Allow) | (Block) | Result | | | |
| :------------------------------- | :---------------------------------- | :--------: | --- | :---------------: | --- |
| `allowedEndpoints: ["/v2/send"]` | `unset` | **all** | 🛑 | **`/v2/send`** | ✅ |
| `unset` | `blockedEndpoints: ["/v1/receive"]` | **all** | ✅ | **`/v1/receive`** | 🛑 |
| `blockedEndpoints: ["/v2"]` | `allowedEndpoints: ["/v2/send"]` | **`/v2*`** | 🛑 | **`/v2/send`** | ✅ |
| Config (Allow) | (Block) | Result | | | |
| :------------- | :------------- | :--------: | --- | :---------------: | --- |
| `/v2/send` | `unset` | **all** | 🛑 | **`/v2/send`** | ✅ |
| `unset` | `!/v1/receive` | **all** | ✅ | **`/v1/receive`** | 🛑 |
| `/v2` | `!/v2/send` | **`/v2*`** | 🛑 | **`/v2/send`** | ✅ |

### Variables

Expand All @@ -260,35 +261,37 @@ See [Placeholders](#placeholders).

```yaml
settings:
variables:
number: "+123400001",
recipients: ["+123400002", "group.id", "user.id"]
message:
variables:
number: "+123400001",
recipients: ["+123400002", "group.id", "user.id"]
```

### Message Templates

To customize the `message` attribute you can use **Message Templates** to build your message by using other Body Keys and Variables.
Use `messageTemplate` to configure:
Use `message.template` to configure:

```yaml
settings:
messageTemplate: |
Your Message:
{{@message}}.
Sent with Secured Signal API.
message:
template: |
Your Message:
{{@message}}.
Sent with Secured Signal API.
```

Message Templates support [Standard Golang Templating](#templating).
Use `@data.key` to reference Body Keys, `#Content_Type` for Headers and `.KEY` for Variables.

### Data Aliases
### Field Mappings

To improve compatibility with other services Secured Signal API provides **Data Aliases** and a built-in `message` Alias.
To improve compatibility with other services Secured Signal API provides **Field Mappings** and a built-in `message` Mapping.

<details>
<summary><strong>Default `message` Aliases</strong></summary>
<summary><strong>Default `message` Mapping</strong></summary>

| Alias | Score | Alias | Score |
| Field | Score | Field | Score |
| ------------ | ----- | ---------------- | ----- |
| msg | 100 | data.content | 9 |
| content | 99 | data.description | 8 |
Expand All @@ -300,23 +303,24 @@ To improve compatibility with other services Secured Signal API provides **Data

</details>

Secured Signal API will pick the best scoring Data Alias (if available) to extract set the Key to the correct Value from the Request Body.
Secured Signal API will pick the best scoring Field (if available) to set the Key to the correct Value from the Request Body.

Data Aliases can be added by setting `dataAliases` in your config:
Field Mappings can be added by setting `message.fieldMappings` in your config:

```yaml
settings:
dataAliases:
"@message":
[
{ alias: "msg", score: 80 },
{ alias: "data.message", score: 79 },
{ alias: "array[0].message", score: 78 },
]
".NUMBER": [{ alias: "phone_number", score: 100 }]
message:
fieldMappings:
"@message":
[
{ field: "msg", score: 80 },
{ field: "data.message", score: 79 },
{ field: "array[0].message", score: 78 },
]
".NUMBER": [{ field: "phone_number", score: 100 }]
```

Use `@` for aliasing Body Keys and `.` for aliasing Variables.
Use `@` for mapping to Body Keys and `.` for mapping to Variables.

## Contributing

Expand Down
43 changes: 0 additions & 43 deletions docs/configuration/data-aliases.md

This file was deleted.

27 changes: 14 additions & 13 deletions docs/configuration/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ but by default the following endpoints are **blocked**, because of Security Conc
> [!NOTE]
> Matching works by checking if the requested Endpoints starts with a Blocked or an Allowed Endpoint

You can modify Blocked Endpoints by configuring `blockedEndpoints` in your config:
You can modify endpoints by configuring `access.endpoints` in your config:

```yaml
settings:
blockedEndpoints: [/v1/register, /v1/unregister, /v1/qrcodelink, /v1/contacts]
access:
endpoints:
- !/v1/register
- !/v1/unregister
- !/v1/qrcodelink
- !/v1/contacts
- /v2/send
```

You can also override Blocked Endpoints by adding Allowed Endpoints to `allowedEndpoints`.
By default adding an endpoint explictly allows access to it, use `!` to block it instead.

```yaml
settings:
allowedEndpoints: [/v2/send]
```

| Config (Allow) | (Block) | Result | | | |
| :------------------------------- | :---------------------------------- | :--------: | --- | :---------------: | --- |
| `allowedEndpoints: ["/v2/send"]` | `unset` | **all** | 🛑 | **`/v2/send`** | ✅ |
| `unset` | `blockedEndpoints: ["/v1/receive"]` | **all** | ✅ | **`/v1/receive`** | 🛑 |
| `blockedEndpoints: ["/v2"]` | `allowedEndpoints: ["/v2/send"]` | **`/v2*`** | 🛑 | **`/v2/send`** | ✅ |
| Config (Allow) | (Block) | Result | | | |
| :------------- | :------------- | :--------: | --- | :---------------: | --- |
| `/v2/send` | `unset` | **all** | 🛑 | **`/v2/send`** | ✅ |
| `unset` | `!/v1/receive` | **all** | ✅ | **`/v1/receive`** | 🛑 |
| `/v2` | `!/v2/send` | **`/v2*`** | 🛑 | **`/v2/send`** | ✅ |
29 changes: 15 additions & 14 deletions docs/configuration/examples/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ api:
logLevel: info

settings:
messageTemplate: |
You've got a Notification:
{{@message}}
At {{@data.timestamp}} on {{@data.date}}.
Send using {{.NUMBER}}.
message:
template: |
You've got a Notification:
{{@message}}
At {{@data.timestamp}} on {{@data.date}}.
Send using {{.NUMBER}}.

variables:
number: "+123400001"
recipients: ["+123400002", "group.id", "user.id"]
variables:
number: "+123400001"
recipients: ["+123400002", "group.id", "user.id"]

dataAliases:
"@message": [{ alias: "msg", score: 100 }]
fieldMappings:
"@message": [{ field: "msg", score: 100 }]

blockedEndpoints:
- /v1/about
allowedEndpoints:
- /v2/send
access:
endpoints:
- !/v1/about
- /v2/send
51 changes: 26 additions & 25 deletions docs/configuration/examples/message-template.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
settings:
messageTemplate: |
{{- $greeting := "Hello" -}}
{{ $greeting }}, {{ @name }}!
{{ if @age -}}
You are {{ @age }} years old.
{{- else -}}
Age unknown.
{{- end }}
Your friends:
{{- range @friends }}
- {{ . }}
{{- else }}
You have no friends.
{{- end }}
Profile details:
{{- range $key, $value := @profile }}
- {{ $key }}: {{ $value }}
{{- end }}
{{ define "footer" -}}
This is the footer for {{ @name }}.
{{- end }}
{{ template "footer" . -}}
------------------------------------
Content-Type: {{ #Content_Type }}
Redacted Auth Header: {{ #Authorization }}
message:
template: |
{{- $greeting := "Hello" -}}
{{ $greeting }}, {{ @name }}!
{{ if @age -}}
You are {{ @age }} years old.
{{- else -}}
Age unknown.
{{- end }}
Your friends:
{{- range @friends }}
- {{ . }}
{{- else }}
You have no friends.
{{- end }}
Profile details:
{{- range $key, $value := @profile }}
- {{ $key }}: {{ $value }}
{{- end }}
{{ define "footer" -}}
This is the footer for {{ @name }}.
{{- end }}
{{ template "footer" . -}}
------------------------------------
Content-Type: {{ #Content_Type }}
Redacted Auth Header: {{ #Authorization }}
11 changes: 7 additions & 4 deletions docs/configuration/examples/token.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
tokens: [LOOOONG_STRING]

overrides:
variables: # Disable Placeholder
blockedEndpoints: # Disable Sending
- /v2/send
dataAliases: # Disable Aliases
message:
fieldMappings: # Disable Mappings
variables: # Disable Placeholder

access:
endpoints: # Disable Sending
- !/v2/send
44 changes: 44 additions & 0 deletions docs/configuration/field-mappings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Field Mappings
---

# Field Mappings

A Compatibility Layer for **Secured Signal API**.

To improve compatibility with other services Secured Signal API provides **Field Mappings** and even a built-in `message` Mapping.

<details>
<summary><strong>Default `message` Mapping</strong></summary>

| Field | Score | Field | Score |
| ------------ | ----- | ---------------- | ----- |
| msg | 100 | data.content | 9 |
| content | 99 | data.description | 8 |
| description | 98 | data.text | 7 |
| text | 20 | data.summary | 6 |
| summary | 15 | data.details | 5 |
| details | 14 | body | 2 |
| data.message | 10 | data | 1 |

</details>

Secured Signal API will pick the highest scoring **Field** (if available) to set the key to the correct value **using the request body**.

Field Mappings can be added by setting `message.fieldMappings` in your config:

```yaml
settings:
message:
fieldMappings:
"@message":
[
{ field: "msg", score: 80 },
{ field: "data.message", score: 79 },
{ field: "array[0].message", score: 78 },
]
".NUMBER": [{ field: "phone_number", score: 100 }]
```

> [!IMPORTANT]
> Use `@` for mapping to Body Keys and `.` for mapping to Variables.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: Message Templates
title: Message Template
---

# Message Templates
# Message Template

Message Templates are the best way to **structure** and **customize** your messages and also very useful for **compatiblity** between different services.

Configure them by using the `messageTemplates` attribute in you config.
Configure them by using the `message.template` attribute in you config.

These support Go Templates (See [Usage](../usage/advanced)) and work by templating the `message` attribute in the request's body.
These support Go Templates (See [Templates](../usage/formatting)) and work by templating the `message` attribute in the request's body.

Here is an example:

Expand All @@ -17,5 +17,8 @@ Here is an example:
```

> [!IMPORTANT]
> Message Templates support [Standard Golang Templating](../usage/advanced).
> Message Templates support [Standard Golang Templating](../usage/formatting).
> Use `@data.key` to reference Body Keys, `#Content_Type` for Headers and `.KEY` for [Variables](./variables).

> [!WARNING]
> Templating using the `Authorization` header results in a redacted string.
Loading