Skip to content

Commit dc0bde0

Browse files
authored
Merge pull request #529 from mchangrh/sanitizeVideoID
Sanitize videoID and minimum UserID length
2 parents fc607d0 + 7c2feb8 commit dc0bde0

File tree

14 files changed

+195
-10
lines changed

14 files changed

+195
-10
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
# Initialization
1616
- uses: actions/checkout@v3
1717
- uses: actions/setup-node@v3
18+
with:
19+
node-version: 18
1820
- run: npm install
1921
- name: Run Tests
2022
timeout-minutes: 5

.github/workflows/eslint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
# Initialization
1616
- uses: actions/checkout@v3
1717
- uses: actions/setup-node@v3
18+
with:
19+
node-version: 18
1820
- run: npm install
1921
- name: Run Tests
2022
timeout-minutes: 5

.github/workflows/generate-sqlite-base.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v3
1818
- uses: actions/setup-node@v3
19+
with:
20+
node-version: 18
1921
- run: npm install
2022
- name: Set config
2123
run: |

.github/workflows/postgres-redis-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
- name: Check running containers
2222
run: docker ps
2323
- uses: actions/setup-node@v3
24+
with:
25+
node-version: 18
2426
- run: npm install
2527
- name: Run Tests
2628
env:

ci.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@
7676
"clientSecret": "testClientSecret",
7777
"redirectUri": "http://127.0.0.1/fake/callback"
7878
},
79-
"minReputationToSubmitFiller": -1
79+
"minReputationToSubmitFiller": -1,
80+
"minUserIDLength": 0
8081
}

config.json.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@
6666
{
6767
"name": "vipUsers"
6868
}]
69-
}
69+
},
70+
"minUserIDLength": 30 // minimum length of UserID to be accepted
7071
}

src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ addDefaults(config, {
166166
},
167167
gumroad: {
168168
productPermalinks: ["sponsorblock"]
169-
}
169+
},
170+
minUserIDLength: 30
170171
});
171172
loadFromEnv(config);
172173
migrate(config);

src/routes/postSkipSegments.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import axios from "axios";
2222
import { vote } from "./voteOnSponsorTime";
2323
import { canSubmit } from "../utils/permissions";
2424
import { getVideoDetails, videoDetails } from "../utils/getVideoDetails";
25+
import * as youtubeID from "../utils/youtubeID";
2526

2627
type CheckResult = {
2728
pass: boolean,
@@ -185,15 +186,23 @@ async function checkUserActiveWarning(userID: string): Promise<CheckResult> {
185186
}
186187

187188
async function checkInvalidFields(videoID: VideoID, userID: UserID, hashedUserID: HashedUserID
188-
, segments: IncomingSegment[], videoDurationParam: number, userAgent: string): Promise<CheckResult> {
189+
, segments: IncomingSegment[], videoDurationParam: number, userAgent: string, service: Service): Promise<CheckResult> {
189190
const invalidFields = [];
190191
const errors = [];
191192
if (typeof videoID !== "string" || videoID?.length == 0) {
192193
invalidFields.push("videoID");
193194
}
194-
if (typeof userID !== "string" || userID?.length < 30) {
195+
if (service === Service.YouTube && config.mode !== "test") {
196+
const sanitizedVideoID = youtubeID.validate(videoID) ? videoID : youtubeID.sanitize(videoID);
197+
if (!youtubeID.validate(sanitizedVideoID)) {
198+
invalidFields.push("videoID");
199+
errors.push("YouTube videoID could not be extracted");
200+
}
201+
}
202+
const minLength = config.minUserIDLength;
203+
if (typeof userID !== "string" || userID?.length < minLength) {
195204
invalidFields.push("userID");
196-
if (userID?.length < 30) errors.push(`userID must be at least 30 characters long`);
205+
if (userID?.length < minLength) errors.push(`userID must be at least ${minLength} characters long`);
197206
}
198207
if (!Array.isArray(segments) || segments.length == 0) {
199208
invalidFields.push("segments");
@@ -484,7 +493,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
484493
//hash the userID
485494
const userID = await getHashCache(paramUserID || "");
486495

487-
const invalidCheckResult = await checkInvalidFields(videoID, paramUserID, userID, segments, videoDurationParam, userAgent);
496+
const invalidCheckResult = await checkInvalidFields(videoID, paramUserID, userID, segments, videoDurationParam, userAgent, service);
488497
if (!invalidCheckResult.pass) {
489498
return res.status(invalidCheckResult.errorCode).send(invalidCheckResult.errorMessage);
490499
}

src/routes/voteOnSponsorTime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
325325
return { status: 400 };
326326
}
327327
// Ignore this vote, invalid
328-
if (paramUserID.length < 30 && config.mode !== "test") {
328+
if (paramUserID.length < config.minUserIDLength) {
329329
return { status: 200 };
330330
}
331331

src/types/config.model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export interface SBSConfig {
9494
}
9595
gumroad: {
9696
productPermalinks: string[],
97-
}
97+
},
98+
minUserIDLength: number
9899
}
99100

100101
export interface WebhookConfig {

0 commit comments

Comments
 (0)