Skip to content

adding validation to Proxy URL to ensure the user entered a protocol #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions electron/app/locales/en/webui.json
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,8 @@
"validation-helper-ingress-path-message-detail": "The path expression must start with / and not having any white space in it",
"validation-helper-ingress-annotation-hint": "Enter a valid annotation name value pair",
"validation-helper-ingress-annotation-message-detail": "The annotation ({{annotation}}) must be a name value pair separate by colon",
"validation-helper-proxy-url-hint": "Enter a valid URL with a protocol specified",
"validation-helper-proxy-url-message-detail": "The proxy URL entered does not have a protocol specified.",

"validation-error-dialog-default-title": "Unknown action failed",

Expand Down
17 changes: 15 additions & 2 deletions webui/src/js/utils/validation-helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
'use strict';
Expand Down Expand Up @@ -32,7 +32,9 @@ function(i18n, Validator, ojvalidationError, RegExpValidator, LengthValidator, N
'(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:' +
'(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])';

const ingressPathRegexText = '^\\/\\S*$';
const ingressPathRegexText = '\\/\\S*';

const proxyUrlRegexText = '[a-zA-Z0-9]+:\\/\\/.+';

this.createValidatableObject = (flowName) => {
class ValidatableObject {
Expand Down Expand Up @@ -140,6 +142,17 @@ function(i18n, Validator, ojvalidationError, RegExpValidator, LengthValidator, N
];
};

this.getProxyUrlValidators = (options) => {
const regExpValidatorOptions = {
pattern: proxyUrlRegexText,
hint: getHintField(options, 'hint', i18n.t('validation-helper-proxy-url-hint')),
messageSummary: getMessageSummary(options),
messageDetail: getMessageDetail(options, 'messageDetail',
i18n.t('validation-helper-proxy-url-message-detail'))
};
return [ new RegExpValidator(regExpValidatorOptions) ];
};

this.getImageTagValidators = (options) => {
const regExpValidatorOptions = {
pattern: imageReferenceRegexText,
Expand Down
7 changes: 4 additions & 3 deletions webui/src/js/viewModels/network-page.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @license
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
* Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
*/
define(['accUtils', 'knockout', 'utils/i18n', 'models/wkt-project',
define(['accUtils', 'knockout', 'utils/i18n', 'models/wkt-project', 'utils/validation-helper',
'ojs/ojinputtext', 'ojs/ojbutton', 'ojs/ojformlayout', 'ojs/ojinputnumber'],
function(accUtils, ko, i18n, project) {
function(accUtils, ko, i18n, project, validationHelper) {
function NetworkPageViewModel() {

this.connected = () => {
Expand Down Expand Up @@ -34,6 +34,7 @@ function(accUtils, ko, i18n, project) {
return i18n.t(`user-settings-dialog-${labelId}`);
};

this.getProxyUrlValidators = () => validationHelper.getProxyUrlValidators();
this.proxyUrl = ko.observable();
this.bypassProxyHosts = ko.observable();
this.requestTimeoutSeconds = ko.observable(5);
Expand Down
12 changes: 7 additions & 5 deletions webui/src/js/viewModels/user-settings-dialog.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/**
* @license
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
* Copyright (c) 2021, 2023, Oracle and/or its affiliates.
* Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
*/
'use strict';

define(['accUtils', 'knockout', 'utils/observable-properties', 'utils/i18n', 'ojs/ojarraydataprovider', 'models/wkt-project',
'utils/wkt-logger', 'ojs/ojknockout', 'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog', 'ojs/ojformlayout',
'ojs/ojswitch', 'ojs/ojselectsingle', 'ojs/ojvalidationgroup', 'ojs/ojinputnumber'],
function(accUtils, ko, utils, i18n, ArrayDataProvider, project, wktLogger) {
define(['accUtils', 'knockout', 'utils/observable-properties', 'utils/i18n', 'ojs/ojarraydataprovider',
'models/wkt-project', 'utils/validation-helper', 'utils/wkt-logger', 'ojs/ojknockout', 'ojs/ojinputtext',
'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojdialog', 'ojs/ojformlayout', 'ojs/ojswitch', 'ojs/ojselectsingle',
'ojs/ojvalidationgroup', 'ojs/ojinputnumber'],
function(accUtils, ko, utils, i18n, ArrayDataProvider, project, validationHelper, wktLogger) {
function UserSettingsDialogModel(payload) {

this.connected = () => {
Expand Down Expand Up @@ -45,6 +46,7 @@ function(accUtils, ko, utils, i18n, ArrayDataProvider, project, wktLogger) {
return payload.isDevMode;
};

this.getProxyUrlValidators = () => validationHelper.getProxyUrlValidators();
this.proxyUrl = ko.observable();
this.bypassProxyHosts = ko.observable();
this.consoleLogLevel = ko.observable(payload.defaults.level);
Expand Down
3 changes: 2 additions & 1 deletion webui/src/js/views/network-page.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2021, 2022, Oracle and/or its affiliates.
Copyright (c) 2021, 2023, Oracle and/or its affiliates.
Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
-->
<div class="wkt-dialog-content" id="networkSettings">
Expand All @@ -11,6 +11,7 @@ <h6><oj-bind-text value="[[labelMapper('title')]]"></oj-bind-text></h6>
<oj-form-layout max-columns="1" direction="row">
<oj-input-text label-hint="[[settingsLabelMapper('https-proxy-url-label')]]"
value="{{proxyUrl}}"
validators="[[getProxyUrlValidators()]]"
help.instruction="[[settingsLabelMapper('https-proxy-url-help')]]">
</oj-input-text>
<oj-input-text label-hint="[[settingsLabelMapper('bypass-proxy-hosts-label')]]"
Expand Down
3 changes: 2 additions & 1 deletion webui/src/js/views/user-settings-dialog.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2021, 2022, Oracle and/or its affiliates.
Copyright (c) 2021, 2023, Oracle and/or its affiliates.
Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
-->
<oj-dialog id="userSettingsDialog" class="wkt-user-settings-dialog" initial-visibility="show">
Expand All @@ -12,6 +12,7 @@ <h6 class="wkt-subheading"><oj-bind-text value="[[labelMapper('proxy-section-tit
<oj-form-layout max-columns="1" direction="row">
<oj-input-text label-hint="[[labelMapper('https-proxy-url-label')]]"
value="{{proxyUrl}}"
validators="[[getProxyUrlValidators()]]"
help.instruction="[[labelMapper('https-proxy-url-help')]]">
</oj-input-text>
<oj-input-text label-hint="[[labelMapper('bypass-proxy-hosts-label')]]"
Expand Down