Skip to content

Commit c06a301

Browse files
committed
feat: Enhance security and simplify JSON response in Stats API
- Remove sensitive information from error messages (player/publisher keys) - Use generic "live" key instead of actual publisher names in JSON response - Move publishers object initialization to success case only - Reduce information disclosure for improved security
1 parent c1b878e commit c06a301

14 files changed

+876
-442
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ COPY --from=builder /usr/local/lib/libsrt* /usr/local/lib
3838
COPY sls.conf /etc/sls/
3939

4040
# expose ports
41-
EXPOSE 4001/udp 8080/tcp
41+
# Publisher port, Player port, HTTP API port
42+
EXPOSE 4001/udp 4000/udp 8080/tcp
4243

4344
# run the server
4445
CMD ["/usr/local/bin/sls", "-c", "/etc/sls/sls.conf"]

Makefile

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,67 @@
1-
SHELL = /bin/sh
2-
MAIN_NAME=sls
3-
CLIENT_NAME=slc
4-
INC_PATH = -I./ -I../ -I./slscore -I./include
5-
LIB_PATH = -L ./lib
6-
LIBRARY_FILE = -lpthread -lz -lsrt
7-
BIN_PATH = ./bin
8-
9-
DEBUG = -g
10-
CFLAGS += $(DEBUG) -w -fcompare-debug-second
11-
12-
LOG_PATH = ./logs
13-
14-
15-
OUTPUT_PATH = ./obj
16-
OBJS = $(OUTPUT_PATH)/SLSLog.o \
17-
$(OUTPUT_PATH)/common.o\
18-
$(OUTPUT_PATH)/conf.o\
19-
$(OUTPUT_PATH)/SLSThread.o\
20-
$(OUTPUT_PATH)/SLSEpollThread.o\
21-
$(OUTPUT_PATH)/SLSManager.o\
22-
$(OUTPUT_PATH)/SLSGroup.o\
23-
$(OUTPUT_PATH)/SLSRole.o\
24-
$(OUTPUT_PATH)/SLSListener.o\
25-
$(OUTPUT_PATH)/SLSRoleList.o\
26-
$(OUTPUT_PATH)/SLSSrt.o\
27-
$(OUTPUT_PATH)/SLSPublisher.o\
28-
$(OUTPUT_PATH)/SLSPlayer.o\
29-
$(OUTPUT_PATH)/SLSRecycleArray.o\
30-
$(OUTPUT_PATH)/SLSMapData.o\
31-
$(OUTPUT_PATH)/SLSMapPublisher.o\
32-
$(OUTPUT_PATH)/SLSRelay.o\
33-
$(OUTPUT_PATH)/SLSPuller.o\
34-
$(OUTPUT_PATH)/SLSPusher.o\
35-
$(OUTPUT_PATH)/SLSRelayManager.o\
36-
$(OUTPUT_PATH)/SLSPullerManager.o\
37-
$(OUTPUT_PATH)/SLSPusherManager.o\
38-
$(OUTPUT_PATH)/SLSMapRelay.o\
39-
$(OUTPUT_PATH)/SLSClient.o\
40-
$(OUTPUT_PATH)/TCPRole.o\
41-
$(OUTPUT_PATH)/SLSArray.o\
42-
$(OUTPUT_PATH)/HttpRoleList.o\
43-
$(OUTPUT_PATH)/HttpClient.o\
44-
$(OUTPUT_PATH)/SLSSyncClock.o\
45-
$(OUTPUT_PATH)/TSFileTimeReader.o
46-
47-
CORE_PATH = slscore
48-
COMMON_FILES = common.hpp
49-
50-
all: $(OBJS)
51-
mkdir -p ${LOG_PATH}
52-
mkdir -p ${OUTPUT_PATH}
53-
mkdir -p ${BIN_PATH}
54-
${CXX} -o ${BIN_PATH}/${MAIN_NAME} srt-live-server.cpp $(OBJS) $(CFLAGS) $(INC_PATH) $(LIB_PATH) $(LIBRARY_FILE)
55-
${CXX} -o ${BIN_PATH}/${CLIENT_NAME} srt-live-client.cpp $(OBJS) $(CFLAGS) $(INC_PATH) $(LIB_PATH) $(LIBRARY_FILE)
56-
#******************************************************************************#
57-
# Build successful ! #
58-
#******************************************************************************#
59-
60-
$(OUTPUT_PATH)/%.o: ./$(CORE_PATH)/%.cpp
61-
${CXX} -c $(CFLAGS) $< -o $@ $(INC_FLAGS)
62-
63-
clean:
64-
rm -f $(OUTPUT_PATH)/*.o
65-
rm -rf $(BIN_PATH)/*
66-
1+
SHELL = /bin/sh
2+
MAIN_NAME=sls
3+
CLIENT_NAME=slc
4+
INC_PATH = -I./ -I../ -I./slscore -I./include
5+
LIB_PATH = -L ./lib
6+
LIBRARY_FILE = -lpthread -lz -lsrt
7+
BIN_PATH = ./bin
8+
9+
DEBUG = -g
10+
CFLAGS += $(DEBUG) -w -fcompare-debug-second
11+
12+
LOG_PATH = ./logs
13+
14+
15+
OUTPUT_PATH = ./obj
16+
OBJS = $(OUTPUT_PATH)/SLSLog.o \
17+
$(OUTPUT_PATH)/common.o\
18+
$(OUTPUT_PATH)/conf.o\
19+
$(OUTPUT_PATH)/SLSThread.o\
20+
$(OUTPUT_PATH)/SLSEpollThread.o\
21+
$(OUTPUT_PATH)/SLSManager.o\
22+
$(OUTPUT_PATH)/SLSGroup.o\
23+
$(OUTPUT_PATH)/SLSRole.o\
24+
$(OUTPUT_PATH)/SLSListener.o\
25+
$(OUTPUT_PATH)/SLSRoleList.o\
26+
$(OUTPUT_PATH)/SLSSrt.o\
27+
$(OUTPUT_PATH)/SLSPublisher.o\
28+
$(OUTPUT_PATH)/SLSPlayer.o\
29+
$(OUTPUT_PATH)/SLSRecycleArray.o\
30+
$(OUTPUT_PATH)/SLSMapData.o\
31+
$(OUTPUT_PATH)/SLSMapPublisher.o\
32+
$(OUTPUT_PATH)/SLSRelay.o\
33+
$(OUTPUT_PATH)/SLSPuller.o\
34+
$(OUTPUT_PATH)/SLSPusher.o\
35+
$(OUTPUT_PATH)/SLSRelayManager.o\
36+
$(OUTPUT_PATH)/SLSPullerManager.o\
37+
$(OUTPUT_PATH)/SLSPusherManager.o\
38+
$(OUTPUT_PATH)/SLSMapRelay.o\
39+
$(OUTPUT_PATH)/SLSClient.o\
40+
$(OUTPUT_PATH)/TCPRole.o\
41+
$(OUTPUT_PATH)/SLSArray.o\
42+
$(OUTPUT_PATH)/HttpRoleList.o\
43+
$(OUTPUT_PATH)/HttpClient.o\
44+
$(OUTPUT_PATH)/SLSSyncClock.o\
45+
$(OUTPUT_PATH)/TSFileTimeReader.o\
46+
$(OUTPUT_PATH)/StreamIdMapper.o
47+
48+
CORE_PATH = slscore
49+
COMMON_FILES = common.hpp
50+
51+
all: $(OBJS)
52+
mkdir -p ${LOG_PATH}
53+
mkdir -p ${OUTPUT_PATH}
54+
mkdir -p ${BIN_PATH}
55+
${CXX} -o ${BIN_PATH}/${MAIN_NAME} srt-live-server.cpp $(OBJS) $(CFLAGS) $(INC_PATH) $(LIB_PATH) $(LIBRARY_FILE)
56+
${CXX} -o ${BIN_PATH}/${CLIENT_NAME} srt-live-client.cpp $(OBJS) $(CFLAGS) $(INC_PATH) $(LIB_PATH) $(LIBRARY_FILE)
57+
#******************************************************************************#
58+
# Build successful ! #
59+
#******************************************************************************#
60+
61+
$(OUTPUT_PATH)/%.o: ./$(CORE_PATH)/%.cpp
62+
${CXX} -c $(CFLAGS) $< -o $@ $(INC_FLAGS)
63+
64+
clean:
65+
rm -f $(OUTPUT_PATH)/*.o
66+
rm -rf $(BIN_PATH)/*
67+

README.md

Lines changed: 126 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,23 @@ if "error while loading shared libraries: libsrt.so.1" occured, please add srt l
5656

5757
use ffmpeg to push camera stream with SRT(on my mac):
5858

59-
$ ./ffmpeg -f avfoundation -framerate 30 -i "0:0" -vcodec libx264 -preset ultrafast -tune zerolatency -flags2 local_header -acodec libmp3lame -g 30 -pkt_size 1316 -flush_packets 0 -f mpegts "srt://[your.sls.ip]:8080?streamid=uplive.sls.com/live/test"
59+
./ffmpeg -re -f avfoundation -i "0:0" -vcodec libx264 -acodec libmp3lame -ar 44100 -ac 1 -f mpegts "srt://[your.sls.ip]:4001?streamid=publisher_id"
6060

6161

62+
2.how to play
63+
-------------
64+
6265
play the SRT stream with ffplay:
6366

64-
./ffplay -fflags nobuffer -i "srt://[your.sls.ip]:8080?streamid=live.sls.com/live/test"
67+
./ffplay -fflags nobuffer -i "srt://[your.sls.ip]:4000?streamid=player_id"
6568

6669

6770
2.test with OBS
6871
---------------
6972

7073
the OBS supports srt protocol to publish stream when version is later than v25.0. you can use the following url:
71-
srt://[your.sls.ip]:8080?streamid=uplive.sls.com/live/test
72-
whith custom service.
74+
srt://[your.sls.ip]:4001?streamid=publisher_id
75+
with custom service.
7376

7477
3.test with srt-live-client
7578
---------------------------
@@ -80,79 +83,146 @@ push ts file as srt url:
8083

8184
cd bin
8285

83-
./slc -r srt://[your.sls.ip]:8080?streamid=uplive.sls.com/live/test -i [the full file name of exist ts file]
86+
./slc -r srt://[your.sls.ip]:4001?streamid=publisher_id -i [the full file name of exist ts file]
8487

8588
play srt url
8689

87-
./slc -r srt://[your.sls.ip]:8080?streamid=live.sls.com/live/test -o [the full file name of ts file to save]
90+
./slc -r srt://[your.sls.ip]:4000?streamid=player_id -o [the full file name of ts file to save]
8891

8992

9093
Note:
9194
=====
9295

93-
1.SLS refer to the RTMP url format(domain/app/stream_name), example: www.sls.com/live/test. The url of SLS must be set in streamid parameter of SRT, which will be the unique identification a stream.
96+
1. SLS uses simple stream IDs without domain/app prefixes. Stream IDs are validated against the streamids.json configuration file.
9497

95-
2.How to distinguish the publisher and player of the same stream? In conf file, you can set parameters of domain_player/domain_publisher and app_player/app_publisher to resolve it. Importantly, the two combination strings of domain_publisher/app_publisher and domain_player/app_player must not be equal in the same server block.
98+
2. Publisher and player connections are distinguished by separate ports (listen_publisher and listen_player).
9699

97100
3.I supply a simple android app for test sls, your can download from https://github.com/Edward-Wu/liteplayer-srt
98101

102+
New Features (v1.5)
103+
===================
104+
105+
Port-based Publisher/Player Separation (Required)
106+
-------------------------------------------------
107+
108+
The server now requires separate ports for publishers and players, using simple stream IDs:
109+
110+
**Configuration:**
111+
```
112+
server {
113+
listen_publisher 4001; # Port for publishers (required)
114+
listen_player 4000; # Port for players (required)
115+
116+
# Other configurations...
117+
}
118+
```
119+
120+
**URLs:**
121+
- Publisher: `srt://server:4001?streamid=stream_id`
122+
- Player: `srt://server:4000?streamid=stream_id`
123+
124+
Stream IDs are now simple values without domain/app prefixes.
125+
126+
Stream ID Mapping (Required)
127+
----------------------------
128+
129+
For enhanced security, different stream IDs must be used for publishers and players. This is configured using a JSON file (`streamids.json`):
130+
131+
```json
132+
[
133+
{
134+
"publisher": "6a204bd89f3c8348afd5c77c717a097a",
135+
"player": "422c6f92cd3b84b65e3cb90fab6544f5"
136+
},
137+
{
138+
"publisher": "1de6ce178679f16b48abc7d8a291cb2e",
139+
"player": "ed8cae86454f037bbcb0856cf1c2f0e3"
140+
}
141+
]
142+
```
143+
144+
With this configuration:
145+
- Publishers must use their specific publisher ID
146+
- Players use their player ID, which is automatically mapped to the publisher ID
147+
- Only configured stream IDs are allowed
148+
- The JSON file must exist and contain valid mappings
149+
150+
Statistics API Enhancement
151+
--------------------------
152+
153+
The `/stats/` endpoint accepts only player IDs for security reasons:
154+
155+
```
156+
GET http://server:8080/stats/422c6f92cd3b84b65e3cb90fab6544f5 # Using player ID
157+
```
158+
159+
The player ID is automatically mapped to the corresponding publisher for statistics retrieval.
160+
161+
Configuration Requirements
162+
--------------------------
163+
164+
The minimal configuration format:
165+
166+
```
167+
server {
168+
listen_publisher 4001; # Required
169+
listen_player 4000; # Required
170+
171+
latency 2000;
172+
backlog 100;
173+
idle_streams_timeout 3;
174+
175+
publisher_exit_delay 10;
176+
record_hls off;
177+
record_hls_segment_duration 10;
178+
}
179+
```
180+
181+
**Breaking Changes:**
182+
- Domain and app configurations have been removed
183+
- Single-port configuration is no longer supported
184+
- Stream IDs are now simple values without prefixes
185+
- Default stream ID configuration has been removed
186+
- Statistics are only accessible via player keys
187+
99188
ReleaseNote
100189
============
101190

102-
v1.2
191+
v1.5
103192
----
104-
1. update the memory mode, in v1.1 which is publisher copy data to eacc player, in v1.2 each publisher put data to a array and all players read data from this array.
105-
2. update the relation of the publisher and player, the player is not a member of publisher. the only relation of them is array data.
106-
3. add push and pull features, support all and hash mode for push, support loop and hash for pull. in cluster mode, you can push a stream to a hash node, and pull this stream from the same hash node.
193+
1. Port-based publisher/player separation with separate listen_publisher and listen_player ports
194+
2. Simplified stream ID format without domain/app prefixes
195+
3. Stream ID mapping with JSON-based security validation
196+
4. Statistics API accessible only via player keys for enhanced security
197+
5. Removed legacy configuration options (domain, app directives)
107198

108-
v1.2.1
109-
------
110-
1. support hostname:port/app in upstreams of pull and push.
199+
v1.4
200+
----
201+
1. support timestamp synchronization of players, resolve the timestamp rollover issue.
202+
2. add on_event_url http callback, you can do some work when publisher/player connect/disconnect.
203+
3. add push and pull features, support all and hash mode for push, support loop and hash for pull. in cluster mode, you can push a stream to a hash node, and pull this stream from the same hash node.
111204

112205
v1.3
113206
----
114-
1. support reload.
115-
2. add idle_streams_timeout feature for relay.
116-
3. change license type from gpl to mit.
207+
1. support hostname:port/app in upstreams of pull and push.
208+
2. support hostname/port/app in upstreams of pull and push.
209+
3. hostname/port/app for upstreams becomes hostname:port/app.
210+
4. support multiple apps in the same worker, improved the reliability.
211+
5. add idle_streams_timeout feature for relay.
117212

118-
v1.4
213+
v1.2
119214
----
120-
1. add http statistic info.
121-
2. add http event notification, on_connect, on_close.
122-
3. add player feature to slc(srt-live-client) tool for pressure test.
123-
124-
v1.4.1
125-
------
126-
1. add publisher feather to slc(srt-live-client) tool, which can push ts file with srt according dts.
127-
2. modify the http bug when host is not available.
128-
129-
v1.4.2
130-
------
131-
1. add remote_ip and remote_port to on_event_url which can be as the unique identification for player or publisher.
132-
133-
v1.4.3
134-
------
135-
1. change the tcp'epoll mode to select mode for compatible MAC os.
136-
2. modify the http check repeat bug for reopen.
137-
138-
v1.4.4
139-
------
140-
1. OBS streaming compatible, OBS support the srt protocol which is later than v25.0.
141-
(https://obsproject.com/forum/threads/obs-studio-25-0-release-candidate.116067/)
142-
143-
v1.4.5
144-
------
145-
1. add hls record feature.
146-
147-
v1.4.6
148-
------
149-
1. update the pid file path from "~/" to "/opt/soft/sls/"
150-
151-
v1.4.7
152-
------
153-
1. update the pid file path from to "/opt/soft/sls/" "/tmp/sls" to avoid the root authority in some case.
215+
1. update the memory mode, in v1.1 which is publisher copy data to eacc player, in v1.2 each publisher put data to a array and all players read data from this array.
216+
2. update the relation of the publisher and player, the player is not a member of publisher. the only relation of them is array data.
154217

218+
v1.1
219+
----
220+
1. support reload configuration file, send SIGUSR1 to sls or call http interface.
221+
2. support listen multiple ports.
222+
3. add on_publisher_timeout and on_timeout_publisher for publisher.
223+
4. add player.on_close_player for player.
224+
5. OBS streaming compatible, OBS support the srt protocol which is later than v25.0.
155225

156-
v1.4.8
157-
------
158-
1. for compatible srt v1.4.1, add the set latency method before setup method
226+
v1.0
227+
----
228+
1. add hls output, if you want to save data to hls, config the record_hls,record_hls_segment_duration parameters. sls open the hls option, and hls can be play with Safari directly.

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ services:
55
dockerfile: Dockerfile
66
platform: linux/amd64
77
ports:
8+
- "4000:4000/udp"
89
- "4001:4001/udp"
910
- "8080:8080/tcp"
11+
volumes:
12+
- ./example_streamids.json:/etc/sls/streamids.json:ro
1013
restart: unless-stopped
1114
networks:
1215
- srt-network

example_streamids.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{"publisher": "internal_pub_001", "player": "live_stream"},
3+
{"publisher": "internal_pub_001", "player": "player_key_123"},
4+
{"publisher": "internal_pub_001", "player": "player_key_456"},
5+
{"publisher": "demo_publisher", "player": "demo"},
6+
{"publisher": "demo_publisher", "player": "demo_viewer"},
7+
{"publisher": "demo_publisher", "player": "viewer_001"},
8+
{"publisher": "demo_publisher", "player": "viewer_002"},
9+
{"publisher": "event_pub_live", "player": "event_stream"},
10+
{"publisher": "event_pub_live", "player": "event_viewer_vip"},
11+
{"publisher": "event_pub_live", "player": "event_viewer_standard"}
12+
]

0 commit comments

Comments
 (0)