- Notifications
You must be signed in to change notification settings - Fork1
Secure Proxy for Signal REST API which adds many QoL and Security Features
License
CodeShellDev/secured-signal-api
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Secure Proxy forSignal Messenger REST API
token-based authentication,endpoint restrictions, placeholders, flexible configuration
🔒 Secure · ⭐️ Configurable · 🚀 Easy to Deploy with Docker
Check out the officialDocumentation for up-to-date Instructions and additional Content.
Prerequisites: You need Docker and Docker Compose installed.
Get the latest version of thedocker-compose.yaml file:
services:signal-api:image:bbernhard/signal-cli-rest-api:latestcontainer_name:signal-apienvironment: -MODE=normalvolumes: -./data:/home/.local/share/signal-clirestart:unless-stoppednetworks:backend:aliases: -signal-apisecured-signal:image:ghcr.io/codeshelldev/secured-signal-api:latestcontainer_name:secured-signalenvironment:API__URL:http://signal-api:8080SETTINGS__MESSAGE__VARIABLES__RECIPIENTS:"[+123400002, +123400003, +123400004]"SETTINGS__MESSAGE__VARIABLES__NUMBER:"+123400001"API__TOKENS:"[LOOOOOONG_STRING]"ports: -"8880:8880"restart:unless-stoppednetworks:backend:aliases: -secured-signal-apinetworks:backend:
And add secure Token(s) toapi.tokens. SeeAPI TOKENs.
Important
In this documentation, we usesec-signal-api:8880 as the host for simplicity.Replace it with your actual container/host IP, port, or hostname.
Before you can send messages via Secured Signal API you must first set upSignal rAPI
Register orlink a Signal account with
signal-cli-rest-apiDeploy
secured-signal-apiwith at least one API tokenConfirm you can send a test message (seeUsage)
Tip
Run setup directly with Signal rAPI.Setup requests via Secured Signal API are blocked. SeeBlocked Endpoints.
Secured Signal API provides 3 Ways to Authenticate
| Method | Example |
|---|---|
| Bearer Auth | AddAuthorization: Bearer API_TOKEN to headers |
| Basic Auth | AddAuthorization: Basic BASE64_STRING (api:API_TOKEN) |
| Query Auth | Append@authorization=API_TOKEN to request URL |
To send a message to+123400002:
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
If you are not comfortable / don't want to hardcode your Number for example and/or Recipients in you, may usePlaceholders in your Request.
How to use:
| Type | Example | Note |
|---|---|---|
| Body | {{@data.key}} | |
| Header | {{#Content_Type}} | - becomes_ |
| Variable | {{.VAR}} | always uppercase |
Where to use:
| Type | Example |
|---|---|
| Body | {"number": "{{ .NUMBER }}", "recipients": "{{ .RECIPIENTS }}"} |
| Query | http://sec-signal-api:8880/v1/receive/?@number={{.NUMBER}} |
| Path | http://sec-signal-api:8880/v1/receive/{{.NUMBER}} |
You can also combine them:
{"content":"{{.NUMBER}} -> {{.RECIPIENTS}}"}In some cases you may not be able to access / modify the Request Body, in that case specify needed values in the Request Query:
http://sec-signal-api:8880/?@key=value
In order to differentiate Injection Queries andregular Queriesyou have to add@ in front of any KeyValue Pair assignment.
Supported types includestrings,ints,arrays andjson dictionaries. SeeFormatting.
There are multiple ways to configure Secured Signal API, you can optionally useconfig.yml aswell as Environment Variables to override the config.
Config files allowYAML formatting and also${ENV} to get Environment Variables.
To change the internal config file location setCONFIG_PATH in yourEnvironment to an absolute path including the filename.extension. (default:/config/config.yml)
This example config shows all of the individual settings that can be applied:
# Example Config (all configurations shown)service:port:8880api:url:http://signal-api:8080tokens:[token1, token2]logLevel:infosettings: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"]fieldMappings:"@message":[{ field: "msg", score: 100 }]access:endpoints: -"!/v1/about" -/v2/sendfieldPolicies:"@number":{value:"+123400003",action:block}
You can also override theconfig.yml file for each individual token by adding configs underTOKENS_PATH (default:config/tokens/)
This way you can permission tokens by further restricting or addingEndpoints,Placeholders, etc.
Here is an example:
tokens:[LOOOONG_STRING]overrides:message:fieldMappings:# Disable Mappingsvariables:# Disable Placeholderaccess:endpoints:# Disable Sending -"!/v2/send"
Secured Signal API uses Golang'sStandard Templating Library.This means that any valid Go template string will also work in Secured Signal API.
Go's templating library is used in the following features:
This makes advancedMessage Templates like this one possible:
settings: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 }}
During Authentication Secured Signal API will try to match the given Token against the list of Tokens inside of these Variables.
api:tokens:[token1, token2, token3]
Important
Using API Tokens is highly recommended, but not mandatory.Some important Security Features won't be available (like default Blocked Endpoints).
Note
Blocked Endpoints can be reactivated by manually configuring them
Since Secured Signal API is just a Proxy you can use all of theSignal REST API endpoints except for...
| Endpoint | |
|---|---|
| /v1/configuration | /v1/unregister |
| /v1/devices | /v1/contacts |
| /v1/register | /v1/accounts |
| /v1/qrcodelink |
These Endpoints are blocked by default due to Security Risks.
Note
Matching usesglob-style patterns:* matches any sequence of characters,? matches a single character and[abc] matches one of the characters in the brackets
You can modify endpoints by configuringaccess.endpoints in your config:
settings:access:endpoints: -"!/v1/register" -"!/v1/unregister" -"!/v1/qrcodelink" -"!/v1/contacts" -/v2/send
By default adding an endpoint explictly allows access to it, use! to block it instead.
Important
When using! to block you must enclose the endpoint with quotes, like in the example above.
| Config (Allow) | (Block) | Result | |||
|---|---|---|---|---|---|
/v2/send | unset | all | 🛑 | /v2/send | ✅ |
unset | !/v1/receive | all | ✅ | /v1/receive | 🛑 |
!/v2* | /v2/send | /v2* | 🛑 | /v2/send | ✅ |
Placeholders can be added undervariables and can then be referenced in the Body, Query or URL.SeePlaceholders.
Note
Every Placeholder Key will be converted into an Uppercase String.Example:number becomesNUMBER in{{.NUMBER}}
settings:message:variables:number:"+123400001",recipients:["+123400002", "group.id", "user.id"]
To customize themessage attribute you can useMessage Templates to build your message by using other Body Keys and Variables.Usemessage.template to configure:
settings:message:template:| Your Message: {{@message}}. Sent with Secured Signal API.
Message Templates supportStandard Golang Templating.Use@data.key to reference Body Keys,#Content_Type for Headers and.KEY for Variables.
Field Policies allow for blocking or specifically allowing certain fields with set values from being used in the requests body or headers.
Configure them by usingaccess.fieldPolicies like so:
settings:access:fieldPolicies:"@number":{ value: "+123400002", action: block }
Set the wanted action on encounter, available options areblock andallow.
Use@ for Body Keys and# for Headers.
To improve compatibility with other services Secured Signal API providesField Mappings and a built-inmessage Mapping.
Default `message` Mapping
| 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 |
Secured Signal API will pick the best scoring Field (if available) to set the Key to the correct Value from the Request Body.
Field Mappings can be added by settingmessage.fieldMappings in your config:
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 }]
Use@ for mapping to Body Keys and. for mapping to Variables.
Found a bug? Want to change or add something?Feel free to open up anIssue or create aPull Request!
Has this Repo been helpful 👍️ to you? Then consider ⭐️'ing this Project.
:)
Are you having Problems setting up Secured Signal API?
No worries check out theDiscussions Tab and ask for help.
We are all Volunteers, so please be friendly and patient.
Logo designed by@CodeShellDev, All Rights Reserved.
This Project is not affiliated with the Signal Foundation.
About
Secure Proxy for Signal REST API which adds many QoL and Security Features
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
