Skip to content
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

fix: return 400 on incorrect client metrics input #4193

Merged
merged 3 commits into from
Jul 11, 2023

Conversation

andreas-unleash
Copy link
Contributor

@andreas-unleash andreas-unleash commented Jul 10, 2023

Wraps the whole registerClientMetrics function with try/catch to return 400 on error

About the changes

Closes # 1-1037

Important files

Discussion points

Screenshot 2023-07-10 at 14 23 13

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
@vercel
Copy link

vercel bot commented Jul 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2023 8:15am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Jul 11, 2023 8:15am

Copy link
Contributor

@thomasheartman thomasheartman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good. What did it return before? 500? And is the error empty now? What happens when it catches?

@thomasheartman
Copy link
Contributor

Just for reference: my comment is because the error message shown in the screenshot you posted looks like it's coming from OpenAPI and not from the try-catch block. It looks like the code is just returning 400 with an empty body, but I might be misreading that.

@andreas-unleash
Copy link
Contributor Author

I was able to reproduce the original error by passing ../../../../../../../../../../../../../../../../etc/passwd\u0000tap-cancelCoreSubscription as a feature name when posting metrics.
Turns out the are 2 errors:

  1. ClientMetricsStore
  2. FeatureToggleStore (via LastSeenService)
Screenshot 2023-07-11 at 09 39 37

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
Copy link
Contributor

@sjaanus sjaanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
@andreas-unleash andreas-unleash merged commit 6601ef1 into main Jul 11, 2023
16 checks passed
@andreas-unleash andreas-unleash deleted the chore/return_4xx_for_incorrect_metrics_input branch July 11, 2023 09:06
gastonfournier pushed a commit that referenced this pull request Jul 25, 2023
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
Wraps the whole `registerClientMetrics` function with try/catch to
return 400 on error
## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #
[1-1037](https://linear.app/unleash/issue/1-1037/return-4xx-error-for-incorrect-metrics-input)

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->
![Screenshot 2023-07-10 at 14 23
13](https://github.com/Unleash/unleash/assets/104830839/5417fb39-ce24-4b70-b3d3-c63374a29a12)

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
gastonfournier added a commit that referenced this pull request Jul 25, 2023
## About the changes
1. Add a test for the failing use case (we can see it
[here](https://github.com/Unleash/unleash/actions/runs/5656229196/job/15322845002?pr=4339#step:5:783)):
```
FAIL src/lib/services/client-metrics/metrics-service-v2.test.ts
  ● process metrics properly even when some names are not url friendly

    ValidationError: "name" must be URL friendly
```
2. Fix and handle this gracefully
3. Added a new toggle to silently ignore bad names: filterInvalidClientMetrics

Fixes: #4193
gastonfournier added a commit that referenced this pull request Jul 25, 2023
1. Add a test for the failing use case (we can see it
[here](https://github.com/Unleash/unleash/actions/runs/5656229196/job/15322845002?pr=4339#step:5:783)):
```
FAIL src/lib/services/client-metrics/metrics-service-v2.test.ts
  ● process metrics properly even when some names are not url friendly

    ValidationError: "name" must be URL friendly
```
2. Fix and handle this gracefully
3. Added a new toggle to silently ignore bad names: filterInvalidClientMetrics

Fixes: #4193
gastonfournier added a commit that referenced this pull request Jul 25, 2023
1. Add a test for the failing use case (we can see it
[here](https://github.com/Unleash/unleash/actions/runs/5656229196/job/15322845002?pr=4339#step:5:783)):
```
FAIL src/lib/services/client-metrics/metrics-service-v2.test.ts
  ● process metrics properly even when some names are not url friendly

    ValidationError: "name" must be URL friendly
```
2. Fix and handle this gracefully
3. Added a new toggle to silently ignore bad names:
filterInvalidClientMetrics

Fixes: #4193
gastonfournier added a commit that referenced this pull request Jul 25, 2023
1. Add a test for the failing use case (we can see it
[here](https://github.com/Unleash/unleash/actions/runs/5656229196/job/15322845002?pr=4339#step:5:783)):
```
FAIL src/lib/services/client-metrics/metrics-service-v2.test.ts
  ● process metrics properly even when some names are not url friendly

    ValidationError: "name" must be URL friendly
```
2. Fix and handle this gracefully
3. Added a new toggle to silently ignore bad names:
filterInvalidClientMetrics

Fixes: #4193
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants