summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAcid Chicken (硫酸鶏) <root@acid-chicken.com>2019-02-06 13:37:20 +0900
committerAya Morisawa <AyaMorisawa4869@gmail.com>2019-02-06 13:37:20 +0900
commit1974d8f58b460953f9c6577f28963dc4985daa67 (patch)
tree3d613f1cc84a4463d4743b0f94e7d5c93cb2014c
parentMerge pull request #4163 from syuilo/dependabot/npm_and_yarn/jsdom-13.2.0 (diff)
downloadmisskey-1974d8f58b460953f9c6577f28963dc4985daa67.tar.gz
misskey-1974d8f58b460953f9c6577f28963dc4985daa67.tar.bz2
misskey-1974d8f58b460953f9c6577f28963dc4985daa67.zip
Add URL validation (#4148)
-rw-r--r--src/config/load.ts11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/config/load.ts b/src/config/load.ts
index fc3e699199..5bb01f3d41 100644
--- a/src/config/load.ts
+++ b/src/config/load.ts
@@ -47,14 +47,21 @@ export default function load() {
return Object.assign(config, mixin);
}
-function validateUrl(url: string) {
+function tryCreateUrl(url: string) {
try {
return new URL(url);
} catch (e) {
- throw `url="${url}" is not a valid URL`;
+ throw `url="${url}" is not a valid URL.`;
}
}
+function validateUrl(url: string) {
+ const result = tryCreateUrl(url);
+ if (result.pathname.replace('/', '').length) throw `url="${url}" is not a valid URL, has a pathname.`;
+ if (!url.includes(result.host)) throw `url="${url}" is not a valid URL, has an invalid hostname.`;
+ return result;
+}
+
function normalizeUrl(url: string) {
return url.endsWith('/') ? url.substr(0, url.length - 1) : url;
}