Validate URL on input instead of automatic rewrite of http to https

Change-Id: I3f3a9c5fb408af1f03ef876456133b331dc4cea3
This commit is contained in:
Michael Albert 2020-04-30 18:45:37 +02:00 committed by Manuel Stahl
parent 437fd70d6d
commit dd022eab04
4 changed files with 15 additions and 13 deletions

View File

@ -90,6 +90,14 @@ const LoginPage = ({ theme }) => {
const errors = {};
if (!values.homeserver) {
errors.homeserver = translate("ra.validation.required");
} else {
if (!values.homeserver.match(/^(http|https):\/\//)) {
errors.homeserver = translate("synapseadmin.auth.protocol_error");
} else if (
!values.homeserver.match(/^(http|https):\/\/[a-zA-Z0-9\-.]+$/)
) {
errors.homeserver = translate("synapseadmin.auth.url_error");
}
}
if (!values.username) {
errors.username = translate("ra.validation.required");

View File

@ -6,6 +6,8 @@ export default {
auth: {
homeserver: "Heimserver",
welcome: "Willkommen bei Synapse-admin",
protocol_error: "Die URL muss mit 'http://' oder 'https://' beginnen",
url_error: "Keine gültige Matrix Server URL",
},
users: {
invalid_user_id:

View File

@ -6,6 +6,8 @@ export default {
auth: {
homeserver: "Homeserver",
welcome: "Welcome to Synapse-admin",
protocol_error: "URL has to start with 'http://' or 'https://'",
url_error: "Not a valid Matrix server URL",
},
users: {
invalid_user_id:

View File

@ -1,13 +1,5 @@
import { fetchUtils } from "react-admin";
const ensureHttpsForUrl = url => {
if (/^https:\/\//i.test(url)) {
return url;
}
const domain = url.replace(/http.?:\/\//g, "");
return "https://" + domain;
};
const stripTrailingSlash = str => {
if (!str) {
return;
@ -17,7 +9,7 @@ const stripTrailingSlash = str => {
const authProvider = {
// called when the user attempts to log in
login: ({ homeserver, username, password }) => {
login: ({ base_url, username, password }) => {
console.log("login ");
const options = {
method: "POST",
@ -28,10 +20,8 @@ const authProvider = {
}),
};
const url = window.decodeURIComponent(homeserver);
const trimmed_url = url.trim().replace(/\s/g, "");
const login_api_url =
ensureHttpsForUrl(trimmed_url) + "/_matrix/client/r0/login";
const decoded_base_url = window.decodeURIComponent(base_url);
const login_api_url = decoded_base_url + "/_matrix/client/r0/login";
return fetchUtils.fetchJson(login_api_url, options).then(({ json }) => {
const normalized_base_url = stripTrailingSlash(