Skip to content

Commit 3da1e52

Browse files
authored
v1.2.0
Update Main for New Release
2 parents 8afcfb0 + d19f75f commit 3da1e52

File tree

29 files changed

+1066
-397
lines changed

29 files changed

+1066
-397
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.github
44
*.yaml
55
*.md
6+
!config/*.yml

.github/templates/README.template.md

Lines changed: 116 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<img align="center" width="1048" height="512" alt="Secure Proxy for Signal REST API" src="https://github.com/CodeShellDev/secured-signal-api/raw/refs/heads/main/logo/landscape" />
22

3-
<h5 align="center">Secure Proxy for <a href="https://github.com/bbernhard/signal-cli-rest-api">Signal REST API</a></h5>
3+
<h5 align="center">Secure Proxy for <a href="https://github.com/bbernhard/signal-cli-rest-api">Signal Messenger REST API</a></h5>
44

5-
## Installation
5+
## Getting Started
66

77
Get the latest version of the `docker-compose.yaml` file:
88

9-
And add secure Token(s) to `API_TOKEN` / `API_TOKENS`. See [API_TOKEN(s)](#api-tokens)
9+
```yaml
10+
{ { file.docker-compose.yaml } }
11+
```
12+
13+
And add secure Token(s) to `api.tokens`. See [API TOKENs](#api-tokens).
1014

1115
> [!IMPORTANT]
1216
> This Documentation will be using `sec-signal-api:8880` as the service host,
13-
> this **won't work**, instead use your containers IP + Port.
17+
> this **is just for simplicty**, instead use your containers or hosts IP + Port.
1418
> Or a hostname if applicable. See [Reverse Proxy](#reverse-proxy)
1519
16-
```yaml
17-
{ { file.docker-compose.yaml } }
18-
```
19-
2020
### Reverse proxy
2121

2222
Take a look at the [traefik](https://github.com/traefik/traefik) implementation:
@@ -76,7 +76,7 @@ Here is a simple example:
7676
curl -X POST http://sec-signal-api:8880/v2/send?@authorization=API_TOKEN
7777
```
7878

79-
Notice the `@` infront of `authorization`. See [Formatting](#format).
79+
Notice the `@` infront of `authorization`. See [KeyValue Pair Injection](#keyvalue-pair-injection).
8080

8181
### Example
8282

@@ -90,9 +90,7 @@ curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer API_T
9090

9191
#### Placeholders
9292

93-
If you are not comfortable / don't want to hardcode your Number and/or Recipients in you may use **Placeholders** in your Request.
94-
95-
Built-in Placeholders: `{{ .NUMBER }}` and `{{ .RECIPIENTS }}`
93+
If you are not comfortable / don't want to hardcode your Number for example and/or Recipients in you, may use **Placeholders** in your Request. See [Custom Variables](#variables).
9694

9795
These Placeholders can be used in the Request Query or the Body of a Request like so:
9896

@@ -121,46 +119,96 @@ http://sec-signal-api:8880/v1/receive/{{.NUMBER}}
121119

122120
In some cases you may not be able to access / modify the Request Body, in that case specify needed values in the Request Query:
123121

124-
Supported types include **strings**, **ints** and **arrays**
125-
126122
`http://sec-signal-api:8880/?@key=value`
127123

128-
| type | example |
129-
| :--------- | :------ |
130-
| string | abc |
131-
| int | 123 |
132-
| array | [1,2,3] |
133-
| array(int) | 1,2,3 |
134-
| array(str) | a,b,c |
135-
136-
##### Format
137-
138124
In order to differentiate Injection Queries and _regular_ Queries
139125
you have to add `@` in front of any KeyValue Pair assignment.
140126

141-
## Environment Variables
127+
Supported types include **strings**, **ints** and **arrays**. See [Formatting](#string-to-type).
128+
129+
## Configuration
130+
131+
There are multiple ways to configure Secured Signal API, you can optionally use `config.yml` aswell as Environment Variables to override the config.
132+
133+
### Config Files
134+
135+
Config files allow **YML** formatting and also `${ENV}` to get Environment Variables.
136+
137+
To change the internal config file location set `CONFIG_PATH` in your **Environment** to an absolute path including the filename.extension. (default: `/config/config.yml`)
138+
139+
This example config shows all of the individual settings that can be applied:
140+
141+
```yaml
142+
{ { file.examples/config.yml } }
143+
```
144+
145+
#### Token Configs
146+
147+
You can also override the `config.yml` file for each individual token by adding configs under `TOKENS_PATH` (default: `config/tokens/`)
148+
149+
This way you can permission tokens by further restricting or adding [Endpoints](#blocked-endpoints), [Placeholders](#variables), etc.
150+
151+
Here is an example:
152+
153+
```yaml
154+
{ { file.examples/token.yml } }
155+
```
156+
157+
### Environment
158+
159+
Suppose you want to set a new [Placeholder](#placeholders) `NUMBER` in your Environment...
160+
161+
```yaml
162+
environment:
163+
VARIABLES__NUMBER: "000"
164+
```
165+
166+
This would internally be converted into `variables.number` matching the config formatting.
167+
168+
> [!IMPORTANT]
169+
> Underscores `_` are removed during Conversion, Double Underscores `__` on the other hand convert the Variable into a nested Object (`__` replaced by `.`)
170+
171+
### String To Type
172+
173+
> [!TIP]
174+
> This formatting applies to almost every situation where the only (allowed) Input Type is a string and other Output Types are needed.
175+
176+
If you are using Environment Variables as an example you won't be able to specify an Array or a Dictionary of items, in that case you can provide a specifically formatted string which will be translated into the correct type...
177+
178+
| type | example |
179+
| :--------- | :---------------- |
180+
| string | abc |
181+
| string | +123 |
182+
| int | 123 |
183+
| int | -123 |
184+
| json | {"a":"b","c":"d"} |
185+
| array(int) | [1,2,3] |
186+
| array(str) | [a,b,c] |
187+
188+
> [!NOTE]
189+
> If you have a string that should not be turned into any other type, then you will need to escape all Type Denotations, `[]` or `{}` (also `-`) with a `\` **Backslash**.
190+
> **Double Backslashes** do exist but you could just leave them out completly.
191+
> An **Odd** number of **Backslashes** **escape** the character in front of them and an **Even** number leave the character **as-is**.
142192

143193
### API Token(s)
144194

145-
Both `API_TOKEN` and `API_TOKENS` support multiple Tokens seperated by a `,` **Comma**.
146195
During Authentication Secured Signal API will try to match the given Token against the list of Tokens inside of these Variables.
147196

148197
```yaml
149-
environment:
150-
API_TOKEN: "token1, token2, token3"
151-
API_TOKENS: "token1, token2, token3"
198+
api:
199+
tokens: [token1, token2, token3]
152200
```
153201

154202
> [!IMPORTANT]
155-
> It is highly recommended to set this Environment Variable
203+
> It is highly recommended use API Tokens
156204

157205
> _What if I just don't?_
158206

159207
Secured Signal API will still work, but important Security Features won't be available
160208
like Blocked Endpoints and any sort of Auth.
161209

162210
> [!NOTE]
163-
> Blocked Endpoints can be reactivated by manually setting them in the Environment
211+
> Blocked Endpoints can be reactivated by manually configuring them
164212

165213
### Blocked Endpoints
166214

@@ -177,53 +225,27 @@ Because Secured Signal API is just a Proxy you can use all of the [Signal REST A
177225
| **/v1/accounts** |
178226
| **/v1/contacts** |
179227

180-
These Endpoints are blocked by default due to Security Risks, but can be modified by setting `BLOCKED_ENDPOINTS` to a Comma seperated List:
228+
These Endpoints are blocked by default due to Security Risks, but can be modified by setting `blockedEndpoints` in your config:
181229

182230
```yaml
183-
environment:
184-
BLOCKED_ENDPOINTS: |
185-
/v1/register,
186-
/v1/unregister,
187-
/v1/qrcodelink,
188-
/v1/contacts,
231+
blockedEndpoints: [/v1/register, /v1/unregister, /v1/qrcodelink, /v1/contacts]
189232
```
190233

191-
#### Variables
192-
193-
By default Secured Signal API provides the following Placeholders:
194-
195-
- **NUMBER** = _ENV_: `NUMBER`
196-
- **RECIPIENTS** = _ENV_: `RECIPIENTS`
197-
198-
### Customization
199-
200-
Placeholders can be added by setting `VARIABLES` inside your Environment.
201-
202-
```yaml
203-
environment:
204-
VARIABLES: |
205-
"NUMBER2": "002",
206-
"GROUP_CHAT_1": [
207-
"user.id", "000", "001", "group.id"
208-
]
209-
```
234+
### Variables
210235

211-
### Recipients
236+
Placeholders can be added under `variables` and can then be referenced in the Body, Query or URL.
237+
See [Placeholders](#placeholders).
212238

213-
Set this Environment Variable to automatically provide default Recipients:
239+
> [!NOTE]
240+
> Every Placeholder Key will be converted into an Uppercase String.
241+
> Example: `number` becomes `NUMBER` in `{{.NUMBER}}`
214242

215243
```yaml
216-
environment:
217-
RECIPIENTS: |
218-
user.id, 000, 001, group.id,
219-
```
220-
221-
example:
222-
223-
```json
224-
{
225-
"recipients": "{{.RECIPIENTS}}"
226-
}
244+
variables:
245+
number: "001",
246+
recipients: [
247+
"user.id", "000", "001", "group.id"
248+
]
227249
```
228250

229251
### Message Aliases
@@ -244,18 +266,34 @@ To improve compatibility with other services Secured Signal API provides aliases
244266

245267
Secured Signal API will pick the best scoring Message Alias (if available) to extract the correct message from the Request Body.
246268

247-
Message Aliases can be added by setting `MESSAGE_ALIASES` to a valid json array containing dictionaries of `alias`, the json key to be used for lookup (use `.` dots for using values from a nested dictionary and `[i]` to get values from an array):
269+
Message Aliases can be added by setting `messageAliases` in your config:
248270

249271
```yaml
250-
environment:
251-
MESSAGE_ALIASES: |
252-
[
253-
{ "alias": "msg", "score": 80 },
254-
{ "alias": "data.message", "score": 79 },
255-
{ "alias": "array[0].message", "score": 78 },
256-
]
272+
messageAliases:
273+
[
274+
{ alias: "msg", score: 80 },
275+
{ alias: "data.message", score: 79 },
276+
{ alias: "array[0].message", score: 78 },
277+
]
257278
```
258279

280+
### Port
281+
282+
To change the Port which Secured Signal API uses, you need to set `server.port` in your config. (default: `8880`)
283+
284+
### Log Level
285+
286+
To change the Log Level set `logLevel` to: (default: `info`)
287+
288+
| Level |
289+
| ------- |
290+
| `info` |
291+
| `debug` |
292+
| `warn` |
293+
| `error` |
294+
| `fatal` |
295+
| `dev` |
296+
259297
## Contributing
260298

261299
Found a bug? Want to change or add something?

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
FROM alpine:latest
22
RUN apk --no-cache add ca-certificates
33

4-
ENV PORT=8880
4+
ENV SERVER__PORT=8880
5+
6+
ENV DEFAULTS_PATH=/app/config/defaults.yml
7+
8+
ENV CONFIG_PATH=/config/config.yml
9+
ENV TOKENS_DIR=/config/tokens
510

611
ARG TARGETOS
712
ARG TARGETARCH
813

914
WORKDIR /app
1015

16+
COPY . .
17+
1118
COPY dist/${TARGETOS}/${TARGETARCH}/app .
1219

1320
RUN ls
1421

15-
CMD ["./app"]
22+
CMD ["./app"]

config/defaults.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
server:
2+
port: 8880
3+
4+
logLevel: INFO
5+
6+
messageAliases:
7+
[
8+
{ alias: msg, score: 100 },
9+
{ alias: content, score: 99 },
10+
{ alias: description, score: 98 },
11+
{ alias: text, score: 20 },
12+
{ alias: summary, score: 15 },
13+
{ alias: details, score: 14 },
14+
15+
{ alias: data.message, score: 10 },
16+
{ alias: data.content, score: 9 },
17+
{ alias: data.description, score: 8 },
18+
{ alias: data.text, score: 7 },
19+
{ alias: data.summary, score: 6 },
20+
{ alias: data.details, score: 5 },
21+
22+
{ alias: payload, score: 3 },
23+
{ alias: body, score: 2 },
24+
{ alias: data, score: 1 },
25+
]
26+
27+
variables:
28+
recipients: ${RECIPIENTS}
29+
number: ${NUMBER}
30+
31+
blockedEndpoints:
32+
- /v1/about
33+
- /v1/configuration
34+
- /v1/devices
35+
- /v1/register
36+
- /v1/unregister
37+
- /v1/qrcodelink
38+
- /v1/accounts
39+
- /v1/contacts

docker-compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ services:
2020
aliases:
2121
- secured-signal-api
2222
environment:
23-
SIGNAL_API_URL: http://signal-api:8080
24-
DEFAULT_RECIPIENTS: '[ "000", "001", "002" ]'
25-
NUMBER: 123456789
26-
API_TOKEN: LOOOOOONG_STRING
23+
API__URL: http://signal-api:8080
24+
VARIABLES__RECIPIENTS: 000,001,002
25+
VARIABLES__NUMBER: 123456789
26+
API__TOKENS: LOOOOOONG_STRING
2727
ports:
2828
- "8880:8880"
2929
restart: unless-stopped

examples/config.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Example Config (all configurations shown)
2+
3+
api:
4+
port: 8880
5+
url: http://signal-api:8080
6+
tokens: [token1, token2]
7+
8+
logLevel: INFO
9+
10+
variables:
11+
number: "000"
12+
recipients: ["001", "group.id", "user.id"]
13+
14+
messageAliases: [{ alias: "msg", score: 100 }]
15+
16+
blockedEndpoints:
17+
- /v1/about

examples/token.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
token: LOOOONG_STRING
2+
3+
overrides:
4+
variables: # Disable Placeholder
5+
blockedEndpoints: # Disable Sending
6+
- /v2/send
7+
messageAliases: # Disable Aliases

0 commit comments

Comments
 (0)