Skip to content

Commit 2889c1d

Browse files
author
OpenShift Bot
authored
Merge pull request #920 from spadgett/improve-path-validation
Merged by openshift-bot
2 parents 2a982a1 + 744bc0b commit 2889c1d

File tree

6 files changed

+70
-14
lines changed

6 files changed

+70
-14
lines changed

app/scripts/controllers/addConfigVolume.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ angular.module('openshiftConsole')
9696
var generateName = $filter('generateName');
9797

9898
var displayError = function(errorMessage, errorDetails) {
99-
$scope.disableInputs = true;
10099
$scope.alerts['attach-persistent-volume-claim'] = {
101100
type: "error",
102101
message: errorMessage,
@@ -225,7 +224,11 @@ angular.module('openshiftConsole')
225224
$window.history.back();
226225
},
227226
function(result) {
228-
displayError("An error occurred attaching the persistent volume claim to the " + $filter('humanizeKind')($routeParams.kind) + ".", getErrorDetails(result));
227+
$scope.disableInputs = false;
228+
var humanizeKind = $filter('humanizeKind');
229+
var sourceKind = humanizeKind(source.kind);
230+
var targetKind = humanizeKind($routeParams.kind);
231+
displayError("An error occurred attaching the " + sourceKind + " to the " + targetKind + ".", getErrorDetails(result));
229232
}
230233
);
231234
};

app/scripts/controllers/attachPVC.js

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ angular.module('openshiftConsole')
168168
},
169169
function(result) {
170170
displayError("An error occurred attaching the persistent volume claim to the " + $filter('humanizeKind')($routeParams.kind) + ".", getErrorDetails(result));
171+
$scope.disableInputs = false;
171172
}
172173
);
173174
}

app/views/add-config-volume.html

+15
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,34 @@ <h3>Keys and Paths</h3>
136136
</div>
137137
<div class="form-group col-md-6">
138138
<label ng-attr-for="path-{{$id}}" class="required">Path</label>
139+
<!--
140+
Regex matches any paths not starting with `/` or containing `..` as path elements.
141+
Use negative lookaheads to assert that the value does not match those patterns.
142+
143+
(?!(\.\.)?\/) do not match strings starting with `/`
144+
(?!\.\.(\/|$)) do not match strings starting with `../` or exactly `..`
145+
(?!.*\/\.\.(\/|$)) do not match strings containing `/../` or ending in `/..`
146+
-->
139147
<input
140148
ng-attr-id="path-{{$id}}"
141149
class="form-control"
142150
ng-class="{ 'has-error': forms.addConfigVolumeForm['path-' + $id].$invalid && forms.addConfigVolumeForm['path-' + $id].$touched }"
143151
type="text"
144152
name="path-{{$id}}"
145153
ng-model="item.path"
154+
ng-pattern="/^(?!\/)(?!\.\.(\/|$))(?!.*\/\.\.(\/|$)).*$/"
146155
required
147156
osc-unique="itemPaths"
148157
placeholder="example: config/app.properties"
149158
autocorrect="off"
150159
autocapitalize="off"
151160
spellcheck="false">
161+
<div class="has-error" ng-show="forms.addConfigVolumeForm['path-' + $id].$error.pattern">
162+
<span class="help-block">
163+
Path must be a relative path. It cannot start with <code>/</code> or
164+
contain <code>..</code> path elements.
165+
</span>
166+
</div>
152167
<div class="has-error" ng-show="forms.addConfigVolumeForm['path-' + $id].$error.oscUnique">
153168
<span class="help-block">
154169
Paths must be unique.

app/views/attach-pvc.html

+23-5
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,20 @@ <h3>Volume</h3>
114114

115115
<div class="form-group">
116116
<label for="volume-name">Volume Name</label>
117+
<!--
118+
Volume name must conform to a DNS label
119+
https://github.com/kubernetes/kubernetes/blob/master/docs/design/identifiers.md
120+
https://github.com/kubernetes/kubernetes/blob/d7a87c228506ed11240049ae95cbb4efb07fd178/pkg/util/validation/validation.go#L61-L70
121+
-->
117122
<input
118123
id="volume-path"
119124
class="form-control"
120125
type="text"
121126
name="volumeName"
122127
ng-model="attach.volumeName"
123128
osc-unique="existingVolumeNames"
129+
ng-pattern="/^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/"
130+
maxlength="63"
124131
placeholder="(generated if empty)"
125132
autocorrect="off"
126133
autocapitalize="off"
@@ -129,11 +136,22 @@ <h3>Volume</h3>
129136
<div>
130137
<span id="volume-name-help" class="help-block">Unique name used to identify this volume. If not specified, a volume name is generated.</span>
131138
</div>
132-
</div>
133-
<div class="has-error" ng-show="attachPVCForm.volumeName.$error.oscUnique">
134-
<span class="help-block">
135-
Volume name already exists. Please choose another name.
136-
</span>
139+
<div class="has-error" ng-show="attachPVCForm.volumeName.$error.pattern && attachPVCForm.volumeName.$touched">
140+
<span class="help-block">
141+
Volume names may only contain lower-case letters, numbers, and dashes.
142+
They may not start or end with a dash.
143+
</span>
144+
</div>
145+
<div class="has-error" ng-show="attachPVCForm.volumeName.$error.maxlength">
146+
<span class="help-block">
147+
Volume names cannot be longer than 63 characters.
148+
</span>
149+
</div>
150+
<div class="has-error" ng-show="attachPVCForm.volumeName.$error.oscUnique">
151+
<span class="help-block">
152+
Volume name already exists. Please choose another name.
153+
</span>
154+
</div>
137155
</div>
138156

139157
<!-- Prompt for containers only if there is more than one. -->

dist/scripts/scripts.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -8197,8 +8197,8 @@ a.volumeMounts || (a.volumeMounts = []), a.volumeMounts.push(b);
81978197
var r = j.createVolume(p, i);
81988198
f.spec.volumes || (f.spec.volumes = []), f.spec.volumes.push(r), c.alerts = {}, g.update(l, e.metadata.name, c.attach.resource, h).then(function() {
81998199
d.history.back();
8200-
}, function(c) {
8201-
n("An error occurred attaching the persistent volume claim to the " + a("humanizeKind")(b.kind) + ".", k(c));
8200+
}, function(d) {
8201+
n("An error occurred attaching the persistent volume claim to the " + a("humanizeKind")(b.kind) + ".", k(d)), c.disableInputs = !1;
82028202
});
82038203
}
82048204
};
@@ -8239,7 +8239,7 @@ c.attach.items.splice(a, 1), o();
82398239
}, i.get(b.project).then(_.spread(function(e, h) {
82408240
c.project = e;
82418241
var i = a("orderByDisplayName"), k = a("getErrorDetails"), m = a("generateName"), n = function(a, b) {
8242-
c.disableInputs = !0, c.alerts["attach-persistent-volume-claim"] = {
8242+
c.alerts["attach-persistent-volume-claim"] = {
82438243
type:"error",
82448244
message:a,
82458245
details:b
@@ -8308,8 +8308,10 @@ items:r
83088308
}
83098309
i.spec.volumes = i.spec.volumes || [], i.spec.volumes.push(s), c.alerts = {}, c.disableInputs = !0, g.update(l, e.metadata.name, c.targetObject, h).then(function() {
83108310
d.history.back();
8311-
}, function(c) {
8312-
n("An error occurred attaching the persistent volume claim to the " + a("humanizeKind")(b.kind) + ".", k(c));
8311+
}, function(d) {
8312+
c.disableInputs = !1;
8313+
var e = a("humanizeKind"), g = e(f.kind), h = e(b.kind);
8314+
n("An error occurred attaching the " + g + " to the " + h + ".", k(d));
83138315
});
83148316
}
83158317
};

dist/scripts/templates.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,13 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
10281028
"</div>\n" +
10291029
"<div class=\"form-group col-md-6\">\n" +
10301030
"<label ng-attr-for=\"path-{{$id}}\" class=\"required\">Path</label>\n" +
1031-
"<input ng-attr-id=\"path-{{$id}}\" class=\"form-control\" ng-class=\"{ 'has-error': forms.addConfigVolumeForm['path-' + $id].$invalid && forms.addConfigVolumeForm['path-' + $id].$touched }\" type=\"text\" name=\"path-{{$id}}\" ng-model=\"item.path\" required osc-unique=\"itemPaths\" placeholder=\"example: config/app.properties\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\">\n" +
1031+
"\n" +
1032+
"<input ng-attr-id=\"path-{{$id}}\" class=\"form-control\" ng-class=\"{ 'has-error': forms.addConfigVolumeForm['path-' + $id].$invalid && forms.addConfigVolumeForm['path-' + $id].$touched }\" type=\"text\" name=\"path-{{$id}}\" ng-model=\"item.path\" ng-pattern=\"/^(?!\\/)(?!\\.\\.(\\/|$))(?!.*\\/\\.\\.(\\/|$)).*$/\" required osc-unique=\"itemPaths\" placeholder=\"example: config/app.properties\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\">\n" +
1033+
"<div class=\"has-error\" ng-show=\"forms.addConfigVolumeForm['path-' + $id].$error.pattern\">\n" +
1034+
"<span class=\"help-block\">\n" +
1035+
"Path must be a relative path. It cannot start with <code>/</code> or contain <code>..</code> path elements.\n" +
1036+
"</span>\n" +
1037+
"</div>\n" +
10321038
"<div class=\"has-error\" ng-show=\"forms.addConfigVolumeForm['path-' + $id].$error.oscUnique\">\n" +
10331039
"<span class=\"help-block\">\n" +
10341040
"Paths must be unique.\n" +
@@ -1165,16 +1171,27 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
11651171
"</div>\n" +
11661172
"<div class=\"form-group\">\n" +
11671173
"<label for=\"volume-name\">Volume Name</label>\n" +
1168-
"<input id=\"volume-path\" class=\"form-control\" type=\"text\" name=\"volumeName\" ng-model=\"attach.volumeName\" osc-unique=\"existingVolumeNames\" placeholder=\"(generated if empty)\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" aria-describedby=\"volume-name-help\">\n" +
1174+
"\n" +
1175+
"<input id=\"volume-path\" class=\"form-control\" type=\"text\" name=\"volumeName\" ng-model=\"attach.volumeName\" osc-unique=\"existingVolumeNames\" ng-pattern=\"/^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/\" maxlength=\"63\" placeholder=\"(generated if empty)\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" aria-describedby=\"volume-name-help\">\n" +
11691176
"<div>\n" +
11701177
"<span id=\"volume-name-help\" class=\"help-block\">Unique name used to identify this volume. If not specified, a volume name is generated.</span>\n" +
11711178
"</div>\n" +
1179+
"<div class=\"has-error\" ng-show=\"attachPVCForm.volumeName.$error.pattern && attachPVCForm.volumeName.$touched\">\n" +
1180+
"<span class=\"help-block\">\n" +
1181+
"Volume names may only contain lower-case letters, numbers, and dashes. They may not start or end with a dash.\n" +
1182+
"</span>\n" +
1183+
"</div>\n" +
1184+
"<div class=\"has-error\" ng-show=\"attachPVCForm.volumeName.$error.maxlength\">\n" +
1185+
"<span class=\"help-block\">\n" +
1186+
"Volume names cannot be longer than 63 characters.\n" +
1187+
"</span>\n" +
11721188
"</div>\n" +
11731189
"<div class=\"has-error\" ng-show=\"attachPVCForm.volumeName.$error.oscUnique\">\n" +
11741190
"<span class=\"help-block\">\n" +
11751191
"Volume name already exists. Please choose another name.\n" +
11761192
"</span>\n" +
11771193
"</div>\n" +
1194+
"</div>\n" +
11781195
"\n" +
11791196
"<div ng-if=\"attach.resource.spec.template.spec.containers.length > 1\">\n" +
11801197
"<div ng-if=\"attach.allContainers\">\n" +

0 commit comments

Comments
 (0)