From 6dd0d190c4fe7cdb4d1fdfa57fe8faef3e4d6ffa Mon Sep 17 00:00:00 2001 From: Lennard Golsch Date: Wed, 2 Dec 2026 12:26:57 +0100 Subject: [PATCH 1/2] fix: fail the Matrix notification on a homeserver without https and on answers other than 2xx --- .github/actions/matrix-notify/action.yml | 20 +++++++++++++++----- README.md | 7 ++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/actions/matrix-notify/action.yml b/.github/actions/matrix-notify/action.yml index 36ce6bf..15faf55 100644 --- a/.github/actions/matrix-notify/action.yml +++ b/.github/actions/matrix-notify/action.yml @@ -6,7 +6,7 @@ inputs: description: Message text, URLs are shown as links by most clients required: true homeserver: - description: Base URL of the homeserver (e.g. 'https://matrix.org'), empty to skip + description: https base URL of the homeserver (e.g. 'https://matrix.org'), empty to skip required: false default: '' room-id: @@ -32,12 +32,22 @@ runs: echo "Matrix is not configured, no message sent" exit 0 fi + if [[ ! "$HOMESERVER" =~ ^https:// ]]; then + echo "::error::homeserver must be the https base URL of the homeserver, e.g. https://matrix.org, not '$(tr -d '[:cntrl:]' <<< "$HOMESERVER")'" + exit 1 + fi ROOM="$(jq -rn --arg room "$ROOM_ID" '$room | @uri')" TXN="${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-$(date +%s%N)" - jq -n --arg body "$MESSAGE" '{msgtype: "m.notice", body: $body}' \ - | curl -sS --fail-with-body --connect-timeout 10 --max-time 30 -X PUT \ + RESPONSE="$(mktemp)" + STATUS="$(jq -n --arg body "$MESSAGE" '{msgtype: "m.notice", body: $body}' \ + | curl -sS --connect-timeout 10 --max-time 30 -o "$RESPONSE" -w '%{http_code}' -X PUT \ -H "Authorization: Bearer ${TOKEN}" \ -H 'Content-Type: application/json' \ --data @- \ - "${HOMESERVER%/}/_matrix/client/v3/rooms/${ROOM}/send/m.room.message/${TXN}" - echo + "${HOMESERVER%/}/_matrix/client/v3/rooms/${ROOM}/send/m.room.message/${TXN}")" \ + || { echo "::error::the message could not be sent to ${HOMESERVER%/}"; exit 1; } + if [[ ! "$STATUS" =~ ^2[0-9][0-9]$ ]]; then + echo "::error::${HOMESERVER%/} answered with HTTP ${STATUS}: $(head -c 500 "$RESPONSE" | tr -d '[:cntrl:]')" + exit 1 + fi + echo "message sent to ${HOMESERVER%/}" diff --git a/README.md b/README.md index eed452e..e159f68 100644 --- a/README.md +++ b/README.md @@ -155,8 +155,13 @@ The room is set by organization variables, which the workflows read from the cal | `MATRIX_HOMESERVER` | `https://matrix.org` | Base URL of the homeserver | | `MATRIX_ROOM_ID` | `!AbCdEf:matrix.org` | Internal id of the room, see its settings | +The base URL is not the server name in the room id: it is `m.homeserver.base_url` of +`https:///.well-known/matrix/client`, e.g. `https://chat.example.org` for `example.org`. + A repository variable with the same name sends the messages of that repository to another room. -Without the variables or without `MATRIX_ACCESS_TOKEN`, no message is sent and nothing fails. +Without the variables or without `MATRIX_ACCESS_TOKEN`, no message is sent and nothing fails. A homeserver that is no +https URL, or any answer of the homeserver but 2xx, fails the step with the answer in its error. The release and +version branch workflows go on with `continue-on-error`, their result does not change. The messages come from a separate Matrix account, which has to be a member of the room. Its access token is shown in Element under Settings, Help & About. The room should not be end-to-end encrypted, as the messages are sent unencrypted. From e70884cfa6f97b934357935c4272e61112ffb795 Mon Sep 17 00:00:00 2001 From: Lennard Golsch Date: Wed, 2 Dec 2026 12:29:44 +0100 Subject: [PATCH 2/2] fix: refuse a Matrix homeserver with whitespace or control characters --- .github/actions/matrix-notify/action.yml | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/matrix-notify/action.yml b/.github/actions/matrix-notify/action.yml index 15faf55..f212759 100644 --- a/.github/actions/matrix-notify/action.yml +++ b/.github/actions/matrix-notify/action.yml @@ -32,7 +32,7 @@ runs: echo "Matrix is not configured, no message sent" exit 0 fi - if [[ ! "$HOMESERVER" =~ ^https:// ]]; then + if [[ ! "$HOMESERVER" =~ ^https://[^[:space:][:cntrl:]]+$ ]]; then echo "::error::homeserver must be the https base URL of the homeserver, e.g. https://matrix.org, not '$(tr -d '[:cntrl:]' <<< "$HOMESERVER")'" exit 1 fi diff --git a/README.md b/README.md index e159f68..7f7c7c8 100644 --- a/README.md +++ b/README.md @@ -152,15 +152,15 @@ The room is set by organization variables, which the workflows read from the cal | Variable | Example | Content | |---------------------|----------------------|-------------------------------------------| -| `MATRIX_HOMESERVER` | `https://matrix.org` | Base URL of the homeserver | +| `MATRIX_HOMESERVER` | `https://matrix.org` | https base URL of the homeserver | | `MATRIX_ROOM_ID` | `!AbCdEf:matrix.org` | Internal id of the room, see its settings | The base URL is not the server name in the room id: it is `m.homeserver.base_url` of `https:///.well-known/matrix/client`, e.g. `https://chat.example.org` for `example.org`. A repository variable with the same name sends the messages of that repository to another room. -Without the variables or without `MATRIX_ACCESS_TOKEN`, no message is sent and nothing fails. A homeserver that is no -https URL, or any answer of the homeserver but 2xx, fails the step with the answer in its error. The release and +Without the variables or without `MATRIX_ACCESS_TOKEN`, no message is sent and nothing fails. A homeserver that is not +an https URL, or any answer of the homeserver but 2xx, fails the step with the answer in its error. The release and version branch workflows go on with `continue-on-error`, their result does not change. The messages come from a separate Matrix account, which has to be a member of the room. Its access token is shown