Skip to content

Commit 5a2a5ea

Browse files
authored
Merge pull request #40 from CodeShellDev/dev
Update Main
2 parents 8e64a6f + be1f159 commit 5a2a5ea

File tree

19 files changed

+180
-228
lines changed

19 files changed

+180
-228
lines changed

.github/templates/README.template.md

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ Notice the `@` infront of `authorization`. See [KeyValue Pair Injection](#keyval
8080

8181
### Example
8282

83-
To send a message to 1234567:
83+
To send a message to `+123400002`:
8484

8585
```bash
86-
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer API_TOKEN" -d '{"message": "Hello World!", "recipients": ["1234567"]}' http://sec-signal-api:8880/v2/send
86+
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer API_TOKEN" -d '{"message": "Hello World!", "recipients": ["+123400002"]}' http://sec-signal-api:8880/v2/send
8787
```
8888

8989
### Advanced
@@ -160,10 +160,10 @@ Suppose you want to set a new [Placeholder](#placeholders) `NUMBER` in your Envi
160160

161161
```yaml
162162
environment:
163-
VARIABLES__NUMBER: "000"
163+
SETTINGS__VARIABLES__NUMBER: "+123400001"
164164
```
165165
166-
This would internally be converted into `variables.number` matching the config formatting.
166+
This would internally be converted into `settings.variables.number` matching the config formatting.
167167

168168
> [!IMPORTANT]
169169
> Underscores `_` are removed during Conversion, Double Underscores `__` on the other hand convert the Variable into a nested Object (`__` replaced by `.`)
@@ -200,52 +200,48 @@ api:
200200
```
201201

202202
> [!IMPORTANT]
203-
> It is highly recommended use API Tokens
204-
205-
> _What if I just don't?_
206-
207-
Secured Signal API will still work, but important Security Features won't be available
208-
like Blocked Endpoints and any sort of Auth.
203+
> Using API Tokens is highly recommended, but not mandatory.
204+
> Some important Security Features won't be available (like default Blocked Endpoints).
209205

210206
> [!NOTE]
211207
> Blocked Endpoints can be reactivated by manually configuring them
212208

213209
### Endpoints
214210

215-
Because Secured Signal API is just a Proxy you can use all of the [Signal REST API](https://github.com/bbernhard/signal-cli-rest-api/blob/master/doc/EXAMPLES.md) endpoints except for...
211+
Since Secured Signal API is just a Proxy you can use all of the [Signal REST API](https://github.com/bbernhard/signal-cli-rest-api/blob/master/doc/EXAMPLES.md) endpoints except for...
212+
213+
| Endpoint | |
214+
| :-------------------- | ------------------ |
215+
| **/v1/about** | **/v1/unregister** |
216+
| **/v1/configuration** | **/v1/qrcodelink** |
217+
| **/v1/devives** | **/v1/contacts** |
218+
| **/v1/register** | **/v1/accounts** |
216219

217-
| Endpoint |
218-
| :-------------------- |
219-
| **/v1/about** |
220-
| **/v1/configuration** |
221-
| **/v1/devives** |
222-
| **/v1/register** |
223-
| **/v1/unregister** |
224-
| **/v1/qrcodelink** |
225-
| **/v1/accounts** |
226-
| **/v1/contacts** |
220+
These Endpoints are blocked by default due to Security Risks.
227221

228222
> [!NOTE]
229-
> Matching works by checking if the requested Endpoints startswith a Blocked or Allowed Endpoint
223+
> Matching works by checking if the requested Endpoints starts with a Blocked or an Allowed Endpoint
230224

231-
These Endpoints are blocked by default due to Security Risks, but can be modified by setting `blockedEndpoints` in your config:
225+
You can modify Blocked Endpoints by configuring `blockedEndpoints` in your config:
232226

233227
```yaml
234-
blockedEndpoints: [/v1/register, /v1/unregister, /v1/qrcodelink, /v1/contacts]
228+
settings:
229+
blockedEndpoints: [/v1/register, /v1/unregister, /v1/qrcodelink, /v1/contacts]
235230
```
236231

237-
Override Blocked Endpoints by explicitly allowing endpoints in `allowedEndpoints`.
232+
You can also override Blocked Endpoints by adding Allowed Endpoints to `allowedEndpoints`.
233+
234+
```yaml
235+
settings:
236+
allowedEndpoints: [/v2/send]
237+
```
238238

239239
| Config (Allow) | (Block) | Result | | | |
240240
| :------------------------------- | :---------------------------------- | :--------: | --- | :---------------: | --- |
241241
| `allowedEndpoints: ["/v2/send"]` | `unset` | **all** | 🛑 | **`/v2/send`** | ✅ |
242242
| `unset` | `blockedEndpoints: ["/v1/receive"]` | **all** | ✅ | **`/v1/receive`** | 🛑 |
243243
| `blockedEndpoints: ["/v2"]` | `allowedEndpoints: ["/v2/send"]` | **`/v2*`** | 🛑 | **`/v2/send`** | ✅ |
244244

245-
```yaml
246-
allowedEndpoints: [/v2/send]
247-
```
248-
249245
### Variables
250246

251247
Placeholders can be added under `variables` and can then be referenced in the Body, Query or URL.
@@ -256,40 +252,38 @@ See [Placeholders](#placeholders).
256252
> Example: `number` becomes `NUMBER` in `{{.NUMBER}}`
257253

258254
```yaml
259-
variables:
260-
number: "001",
261-
recipients: [
262-
"user.id", "000", "001", "group.id"
263-
]
255+
settings:
256+
variables:
257+
number: "+123400001",
258+
recipients: ["+123400002", "group.id", "user.id"]
264259
```
265260

266261
### Message Aliases
267262

268263
To improve compatibility with other services Secured Signal API provides aliases for the `message` attribute by default:
269264

270-
| Alias | Score |
271-
| ----------- | ----- |
272-
| msg | 100 |
273-
| content | 99 |
274-
| description | 98 |
275-
| text | 20 |
276-
| body | 15 |
277-
| summary | 10 |
278-
| details | 9 |
279-
| payload | 2 |
280-
| data | 1 |
265+
| Alias | Score | Alias | Score |
266+
| ------------ | ----- | ---------------- | ----- |
267+
| msg | 100 | data.content | 9 |
268+
| content | 99 | data.description | 8 |
269+
| description | 98 | data.text | 7 |
270+
| text | 20 | data.summary | 6 |
271+
| summary | 15 | data.details | 5 |
272+
| details | 14 | body | 2 |
273+
| data.message | 10 | data | 1 |
281274

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

284277
Message Aliases can be added by setting `messageAliases` in your config:
285278

286279
```yaml
287-
messageAliases:
288-
[
289-
{ alias: "msg", score: 80 },
290-
{ alias: "data.message", score: 79 },
291-
{ alias: "array[0].message", score: 78 },
292-
]
280+
settings:
281+
messageAliases:
282+
[
283+
{ alias: "msg", score: 80 },
284+
{ alias: "data.message", score: 79 },
285+
{ alias: "array[0].message", score: 78 },
286+
]
293287
```
294288

295289
### Port

config/defaults.yml

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
server:
22
port: 8880
33

4-
logLevel: INFO
4+
logLevel: info
55

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 },
6+
settings:
7+
messageAliases:
8+
[
9+
{ alias: msg, score: 100 },
10+
{ alias: content, score: 99 },
11+
{ alias: description, score: 98 },
12+
{ alias: text, score: 20 },
13+
{ alias: summary, score: 15 },
14+
{ alias: details, score: 14 },
1415

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 },
16+
{ alias: data.message, score: 10 },
17+
{ alias: data.content, score: 9 },
18+
{ alias: data.description, score: 8 },
19+
{ alias: data.text, score: 7 },
20+
{ alias: data.summary, score: 6 },
21+
{ alias: data.details, score: 5 },
2122

22-
{ alias: payload, score: 3 },
23-
{ alias: body, score: 2 },
24-
{ alias: data, score: 1 },
25-
]
23+
{ alias: body, score: 2 },
24+
{ alias: data, score: 1 },
25+
]
2626

27-
variables:
28-
recipients: ${RECIPIENTS}
29-
number: ${NUMBER}
27+
variables:
28+
recipients: ${RECIPIENTS}
29+
number: ${NUMBER}
3030

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
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: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@ services:
66
- MODE=normal
77
volumes:
88
- ./data:/home/.local/share/signal-cli
9+
restart: unless-stopped
910
networks:
1011
backend:
1112
aliases:
1213
- signal-api
13-
restart: unless-stopped
1414

1515
secured-signal:
1616
image: ghcr.io/codeshelldev/secured-signal-api:latest
1717
container_name: secured-signal
18-
networks:
19-
backend:
20-
aliases:
21-
- secured-signal-api
2218
environment:
2319
API__URL: http://signal-api:8080
24-
VARIABLES__RECIPIENTS: '[000,001,002]'
25-
VARIABLES__NUMBER: 123456789
26-
API__TOKENS: '[LOOOOOONG_STRING]'
20+
SETTINGS__VARIABLES__RECIPIENTS:
21+
["+123400002", "+123400003", "+123400004"]
22+
SETTINGS__VARIABLES__NUMBER: "+123400001"
23+
API__TOKENS: [LOOOOOONG_STRING]
2724
ports:
2825
- "8880:8880"
2926
restart: unless-stopped
27+
networks:
28+
backend:
29+
aliases:
30+
- secured-signal-api
3031

3132
networks:
3233
backend:

examples/config.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ api:
77

88
logLevel: INFO
99

10-
variables:
11-
number: "000"
12-
recipients: ["001", "group.id", "user.id"]
10+
settings:
11+
variables:
12+
number: "+123400001"
13+
recipients: ["+123400002", "group.id", "user.id"]
1314

14-
messageAliases: [{ alias: "msg", score: 100 }]
15+
messageAliases: [{ alias: "msg", score: 100 }]
1516

16-
blockedEndpoints:
17-
- /v1/about
18-
allowedEndpoints:
19-
- /v2/send
17+
blockedEndpoints:
18+
- /v1/about
19+
allowedEndpoints:
20+
- /v2/send

examples/traefik.docker-compose.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ services:
22
secured-signal:
33
image: ghcr.io/codeshelldev/secured-signal-api:latest
44
container_name: secured-signal
5-
networks:
6-
proxy:
7-
backend:
8-
aliases:
9-
- secured-signal-api
105
environment:
116
API__URL: http://signal-api:8080
12-
VARIABLES__RECIPIENTS: '[000,001,002]'
13-
VARIABLES__NUMBER: 123456789
14-
API__TOKENS: '[LOOOOOONG_STRING]'
7+
SETTINGS__VARIABLES__RECIPIENTS: ["123400002", "123400003", "123400004"]
8+
SETTINGS__VARIABLES__NUMBER: "+123400001"
9+
API__TOKENS: [LOOOOOONG_STRING]
1510
labels:
1611
- traefik.enable=true
1712
- traefik.http.routers.signal-api.rule=Host(`signal-api.mydomain.com`)
@@ -22,6 +17,11 @@ services:
2217
- traefik.http.services.signal-api-svc.loadbalancer.server.port=8880
2318
- traefik.docker.network=proxy
2419
restart: unless-stopped
20+
networks:
21+
proxy:
22+
backend:
23+
aliases:
24+
- secured-signal-api
2525

2626
networks:
2727
backend:

go.mod

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ module github.com/codeshelldev/secured-signal-api
22

33
go 1.25.1
44

5-
require (
6-
go.uber.org/zap v1.27.0
7-
gopkg.in/yaml.v3 v3.0.1
8-
)
5+
require go.uber.org/zap v1.27.0
96

107
require (
118
github.com/fsnotify/fsnotify v1.9.0 // indirect
12-
github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
9+
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
1310
github.com/knadh/koanf/maps v0.1.2 // indirect
1411
github.com/knadh/koanf/parsers/yaml v1.1.0
1512
github.com/knadh/koanf/providers/confmap v1.0.0
1613
github.com/knadh/koanf/providers/env/v2 v2.0.0
1714
github.com/knadh/koanf/providers/file v1.2.0
18-
github.com/knadh/koanf/v2 v2.2.2
15+
github.com/knadh/koanf/v2 v2.3.0
1916
github.com/mitchellh/copystructure v1.2.0 // indirect
2017
github.com/mitchellh/reflectwalk v1.0.2 // indirect
2118
go.uber.org/multierr v1.11.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
44
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
5-
github.com/go-viper/mapstructure/v2 v2.3.0 h1:27XbWsHIqhbdR5TIC911OfYvgSaW93HM+dX7970Q7jk=
6-
github.com/go-viper/mapstructure/v2 v2.3.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
5+
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
6+
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
77
github.com/knadh/koanf/maps v0.1.2 h1:RBfmAW5CnZT+PJ1CVc1QSJKf4Xu9kxfQgYVQSu8hpbo=
88
github.com/knadh/koanf/maps v0.1.2/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI=
99
github.com/knadh/koanf/parsers/yaml v1.1.0 h1:3ltfm9ljprAHt4jxgeYLlFPmUaunuCgu1yILuTXRdM4=
@@ -14,8 +14,8 @@ github.com/knadh/koanf/providers/env/v2 v2.0.0 h1:Ad5H3eun722u+FvchiIcEIJZsZ2M6o
1414
github.com/knadh/koanf/providers/env/v2 v2.0.0/go.mod h1:1g01PE+Ve1gBfWNNw2wmULRP0tc8RJrjn5p2N/jNCIc=
1515
github.com/knadh/koanf/providers/file v1.2.0 h1:hrUJ6Y9YOA49aNu/RSYzOTFlqzXSCpmYIDXI7OJU6+U=
1616
github.com/knadh/koanf/providers/file v1.2.0/go.mod h1:bp1PM5f83Q+TOUu10J/0ApLBd9uIzg+n9UgthfY+nRA=
17-
github.com/knadh/koanf/v2 v2.2.2 h1:ghbduIkpFui3L587wavneC9e3WIliCgiCgdxYO/wd7A=
18-
github.com/knadh/koanf/v2 v2.2.2/go.mod h1:abWQc0cBXLSF/PSOMCB/SK+T13NXDsPvOksbpi5e/9Q=
17+
github.com/knadh/koanf/v2 v2.3.0 h1:Qg076dDRFHvqnKG97ZEsi9TAg2/nFTa9hCdcSa1lvlM=
18+
github.com/knadh/koanf/v2 v2.3.0/go.mod h1:gRb40VRAbd4iJMYYD5IxZ6hfuopFcXBpc9bbQpZwo28=
1919
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
2020
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
2121
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=

internals/proxy/middlewares/body.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strconv"
88

99
middlewareTypes "github.com/codeshelldev/secured-signal-api/internals/proxy/middlewares/types"
10-
"github.com/codeshelldev/secured-signal-api/utils"
10+
jsonutils "github.com/codeshelldev/secured-signal-api/utils/jsonutils"
1111
log "github.com/codeshelldev/secured-signal-api/utils/logger"
1212
request "github.com/codeshelldev/secured-signal-api/utils/request"
1313
)
@@ -90,7 +90,7 @@ func getMessage(aliases []middlewareTypes.MessageAlias, data map[string]any) (st
9090
func processAlias(alias middlewareTypes.MessageAlias, data map[string]any) (string, int, bool) {
9191
aliasKey := alias.Alias
9292

93-
value, ok := utils.GetByPath(aliasKey, data)
93+
value, ok := jsonutils.GetByPath(aliasKey, data)
9494

9595
aliasValue, isStr := value.(string)
9696

0 commit comments

Comments
 (0)