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.
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(🩹): error handling in CSRF token storage retrieval #3021
base: main
Are you sure you want to change the base?
Fix(🩹): error handling in CSRF token storage retrieval #3021
Changes from 2 commits
2f82476
750c7f5
a53d206
aae5a6c
97be135
c327066
5ab83ba
3005913
f301d39
98bbb40
41266f3
7075406
f5933a6
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle potential errors from
getRawFromStorage
properly.The error from
getRawFromStorage
is checked, but the handling could be more robust. Consider adding specific error handling for different types of errors that could be returned:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai it doesn't make sense, can you explain why I need to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@renanbastos93 The suggestion to handle specific errors from
getRawFromStorage
more robustly is aimed at improving the middleware's ability to respond appropriately to different failure scenarios. Currently, the error handling in the switch case forGET
,HEAD
,OPTIONS
, andTRACE
methods does not differentiate between the types of errors that could be returned fromgetRawFromStorage
. This function could return errors likeErrNotGetStorage
, which specifically indicates issues in retrieving data from storage.By handling such specific errors distinctly, you can tailor the middleware's response to better suit the nature of the error. For example, if
ErrNotGetStorage
is encountered, it might be beneficial to log this as a critical error or perform a specific action, because it indicates a failure in the storage backend, which is critical for CSRF protection. This makes the error handling more granular and can help in debugging and maintaining the system more effectively.Let me know if this clarifies the suggestion or if there's anything else you'd like to discuss!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai I got it I am waiting for the team comment for that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@renanbastos93, understood! It's great to hear that you're considering the suggestion and discussing it further with your team. If you need any more information or further clarification as you move forward, feel free to reach out. I'm here to help!
Check failure on line 213 in middleware/csrf/csrf.go
GitHub Actions / lint
Check failure on line 213 in middleware/csrf/csrf.go
GitHub Actions / lint
Check failure on line 225 in middleware/csrf/csrf.go
GitHub Actions / lint
Check failure on line 225 in middleware/csrf/csrf.go
GitHub Actions / lint
Check failure on line 233 in middleware/csrf/csrf.go
GitHub Actions / lint
Check failure on line 233 in middleware/csrf/csrf.go
GitHub Actions / lint
Check failure on line 29 in middleware/csrf/session_manager.go
GitHub Actions / lint
Check failure on line 29 in middleware/csrf/session_manager.go
GitHub Actions / lint
Check warning on line 32 in middleware/csrf/session_manager.go
Codecov / codecov/patch
middleware/csrf/session_manager.go#L32
Check failure on line 44 in middleware/csrf/storage_manager.go
GitHub Actions / lint
Check failure on line 44 in middleware/csrf/storage_manager.go
GitHub Actions / lint
Check warning on line 48 in middleware/csrf/storage_manager.go
Codecov / codecov/patch
middleware/csrf/storage_manager.go#L46-L48
Check warning on line 66 in middleware/csrf/storage_manager.go
Codecov / codecov/patch
middleware/csrf/storage_manager.go#L64-L66
Check warning on line 81 in middleware/csrf/storage_manager.go
Codecov / codecov/patch
middleware/csrf/storage_manager.go#L79-L81