Repository navigation
fix(anomaly): validate config bounds, reject unbounded window sizes, and map validation errors to 400 (closes #909) - #915
Open
mopxam-art wants to merge 1 commit into
Conversation
…and map validation errors to 400 (closes Heliobond#909)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Closes #909 by adding upper and lower bounds checking to anomaly detection parameters in
validateAnomalyConfig, rejecting unbounded window sizes (such as1e15), requiring integer values for window size and baseline, enforcing thatminBaseline <= trendWindowSize, and wrappingPUT /v1/anomaly/configso thatAnomalyValidationErroris cleanly translated to HTTP 400 Bad Request instead of an unhandled HTTP 500 error.Changes
src/lib/anomaly.ts:MAX_SENSITIVITY_Z_SCORE = 20,MAX_TREND_WINDOW_SIZE = 1000,MIN_TREND_WINDOW_SIZE = 2,MAX_TREND_DEVIATION_PCT = 1000,MAX_MIN_BASELINE = 500.trendWindowSizeandminBaseline.minBaselinecannot exceedtrendWindowSize.src/routes/anomaly-admin.ts:PUT /configintry / catchblock and passedAnomalyValidationErrortonext(badRequest(err.message))(HTTP 400).src/middleware/errors.ts:AnomalyValidationErrorinerrorHandlermapping to HTTP 400bad_request.src/__tests__/anomaly-admin-5d-matrix.test.ts:Verification
npx jest src/__tests__/anomaly-admin-5d-matrix.test.ts).npx tsc --noEmit).npm run build).