Skip to content

Commit 3cc1bb6

Browse files
add target_url validation
1 parent 3a84ceb commit 3cc1bb6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

.github/actions/set-status/action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,31 @@ runs:
5353
if (!sha.match(/^[0-9a-z]+$/)) {
5454
inputValidationErrors.push('"sha" must be an alphanumeric string.');
5555
}
56+
if (target_url && target_url.length > 0) {
57+
if (target_url.length > 2048) {
58+
inputValidationErrors.push('"target-url" must be less than 2048 characters.');
59+
}
60+
61+
try {
62+
const url = new URL(target_url);
63+
64+
if (url.protocol !== 'https:') {
65+
inputValidationErrors.push('"target-url" must use HTTPS protocol.');
66+
}
67+
68+
const allowedHostnames = ['github.com', 'api.github.com'];
69+
if (!allowedHostnames.includes(url.hostname)) {
70+
inputValidationErrors.push(`"target-url" must be one of: ${allowedHostnames.join(', ')}.`);
71+
}
72+
73+
} catch (error) {
74+
if (error instanceof TypeError && error.message.includes('Invalid URL')) {
75+
inputValidationErrors.push('"target-url" must be a valid URL format.');
76+
} else {
77+
inputValidationErrors.push(`"target-url" validation failed: ${error.message}`);
78+
}
79+
}
80+
}
5681
if (inputValidationErrors.length > 0) {
5782
inputValidationErrors.forEach(core.error);
5883
process.exit(1);

0 commit comments

Comments
 (0)