Skip to content

Commit 3d91f51

Browse files
authored
Merge pull request #872 from pradnya-orchestral/Webscan_errordisclosure
Fixed integer overflow issue
2 parents d88b562 + 0dbb72a commit 3d91f51

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

apps/st2-actions/actions-details.component.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
} from '@stackstorm/module-panel';
4949
import Time from '@stackstorm/module-time';
5050

51+
5152
@connect((state) => {
5253
const { action, executions, entrypoint } = state;
5354
return { action, executions, entrypoint };
@@ -126,9 +127,10 @@ export default class ActionsDetails extends React.Component {
126127
}
127128
}
128129

130+
131+
129132
componentDidUpdate(prevProps) {
130133
const { id } = this.props;
131-
132134
if (id && id !== prevProps.id) {
133135
this.fetchAction(id);
134136
}
@@ -192,6 +194,23 @@ export default class ActionsDetails extends React.Component {
192194
;
193195
}
194196

197+
minMax (value) {
198+
if (value < 0 || value > 2492000) {
199+
return true;
200+
}
201+
return false;
202+
}
203+
204+
isValidInt (value) {
205+
for ( let n = 0; n < value.length; n += 1) {
206+
const digit = (value.charCodeAt(n) >= 48 && value.charCodeAt(n) <= 57) || value.charCodeAt(n) === 45 || value.charCodeAt(n) === 8;
207+
if (!digit) {
208+
return true;
209+
}
210+
}
211+
return false;
212+
}
213+
195214
handleSection(section) {
196215
const { id } = this.props;
197216
return this.props.handleNavigate({ id, section });
@@ -220,13 +239,11 @@ export default class ActionsDetails extends React.Component {
220239

221240
handleRun(e, ...args) {
222241
e.preventDefault();
223-
224242
return this.props.handleRun(...args);
225243
}
226244

227245
render() {
228246
const { section, action, executions, entrypoint } = this.props;
229-
230247
if (!action) {
231248
return null;
232249
}
@@ -253,7 +270,15 @@ export default class ActionsDetails extends React.Component {
253270
{ section === 'general' ? (
254271
<DetailsBody>
255272
<DetailsToolbar key="toolbar">
256-
<Button value="Run" data-test="run_submit" onClick={(e) => this.handleRun(e, action.ref, this.state.runValue, this.state.runTrace || undefined)} />
273+
<Button
274+
disabled={
275+
(this.state.runValue && this.state.runValue.timeout && this.minMax(this.state.runValue.timeout)) ||
276+
(this.state.runValue && this.state.runValue.limit && this.minMax(this.state.runValue.limit)) ||
277+
(this.state.runValue && this.state.runValue.timeout && this.isValidInt(this.state.runValue.timeout)) ||
278+
(this.state.runValue && this.state.runValue.limit && this.isValidInt(this.state.runValue.limit))
279+
}
280+
value="Run" data-test="run_submit" onClick={(e) => this.handleRun(e, action.ref, this.state.runValue, this.state.runTrace || undefined)}
281+
/>
257282
<Button flat value="Preview" onClick={() => this.handleToggleRunPreview()} />
258283
<DetailsToolbarSeparator />
259284
{ action.runner_type === 'mistral-v2' || action.runner_type === 'orquesta' ? (

modules/st2-auto-form/fields/base.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ export class BaseTextField extends React.Component {
8585

8686
handleChange(e, value) {
8787
e.stopPropagation();
88-
88+
8989
const invalid = this.validate(value, this.props.spec);
90-
91-
this.setState({ value, invalid }, this.props.onChange && !invalid ? this.emitChange : undefined);
90+
91+
if (this.props.name === 'timeout' || this.props.name === 'limit') {
92+
this.setState({ value, invalid }, this.props.onChange ? this.emitChange : undefined);
93+
}
94+
else {
95+
this.setState({ value, invalid }, this.props.onChange && !invalid ? this.emitChange : undefined);
96+
}
9297
}
9398

9499
emitChange() {

modules/st2-auto-form/fields/integer.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ export default class IntegerField extends BaseTextField {
2424
return v;
2525
}
2626

27-
return v !== '' ? validator.toInt(v, 10) : void 0;
27+
if (this.props.name === 'timeout' || this.props.name === 'limit') {
28+
return v ;
29+
}
30+
else {
31+
return v !== '' ? validator.toInt(v, 10) : void 0;
32+
}
2833
}
2934

3035
toStateValue(v) {
@@ -41,6 +46,24 @@ export default class IntegerField extends BaseTextField {
4146
return invalid;
4247
}
4348

49+
if (spec._name === 'timeout' || spec._name === 'limit') {
50+
for (let n = 0; n < v.length; n += 1) {
51+
const digit = (v.charCodeAt(n) >= 48 && v.charCodeAt(n) <= 57) || v.charCodeAt(n) === 45 || v.charCodeAt(n) === 8;
52+
if (!digit) {
53+
return `'${v}' must be a positive integer`;
54+
}
55+
else {
56+
if (v < 0) {
57+
return 'Value must be > 0';
58+
}
59+
else if (v > 2592000) {
60+
return 'Value must be <= 2592000';
61+
}
62+
63+
}
64+
}
65+
}
66+
4467
return v && !validator.isInt(v) && `'${v}' is not an integer`;
4568
}
4669
}

0 commit comments

Comments
 (0)