Skip to content

Commit 4a812e2

Browse files
committed
feat: prevent many add-api submissions which are not API definitions
1 parent fe5db15 commit 4a812e2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/add-api.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@
2121
form.onsubmit = addApi;
2222
function addApi(e) {
2323
e.preventDefault();
24+
25+
try {
26+
let up = new URL(form.url.value);
27+
if (!up.pathname || up.pathname === '/') {
28+
alert('Please specify a machine-readable API definition location, not a website root URL');
29+
return(false);
30+
}
31+
if (up.pathname.endsWith('.html')) {
32+
alert('Please specify a machine-readable API definition location, not an html page');
33+
return(false);
34+
}
35+
if ((up.hostname.indexOf('localhost')>=0) || (up.hostname.indexOf('127.0.0.1')>=0)) {
36+
alert('Please specify a non-localhost URL');
37+
return(false);
38+
}
39+
}
40+
catch (ex) {
41+
alert(ex.message);
42+
return false;
43+
}
44+
2445
var details = {
2546
format: form['spec-format'].value,
2647
official: form.official.value,

0 commit comments

Comments
 (0)