-
Notifications
You must be signed in to change notification settings - Fork 9
Perf fix: create a unified should_skip_attack_scan #490
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
Draft
bitterpanda63
wants to merge
7
commits into
main
Choose a base branch
from
perf-fix-do-not-fetch-thread-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
edab74b
create a unified should_skip_attack_scan
bitterpanda63 8bc9234
rename cached forced_protection_off to should_skip_attack_scan
bitterpanda63 db64b94
also rename context var in should_skip_attack_scan.py
bitterpanda63 b63e77e
Add in context exists checks
bitterpanda63 ae58c95
Update vuln test cases
bitterpanda63 051c622
set I/O calls limit to 25
bitterpanda63 639628b
Merge branch 'main' into perf-fix-do-not-fetch-thread-cache
bitterpanda63 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from aikido_zen.thread.thread_cache import get_cache | ||
| from aikido_zen.helpers.protection_forced_off import protection_forced_off | ||
| from aikido_zen.helpers.logging import logger | ||
| from aikido_zen.context import Context | ||
|
|
||
|
|
||
| def should_skip_attack_scan(context: Context) -> bool: | ||
| """ | ||
| Check if protection is forced off or IP bypassed using cache stored in the context. | ||
| This function assumes that the thread cache has already been retrieved | ||
| and uses it to determine if protection is forced off for the given context. | ||
| """ | ||
| if not context: | ||
| return False | ||
|
|
||
| if context.should_skip_attack_scan is not None: | ||
| # Retrieving from cache, we don't want to constantly go through | ||
| # all the endpoints for every single vulnerability check. | ||
| return context.should_skip_attack_scan | ||
|
|
||
| thread_cache = get_cache() | ||
| if not thread_cache: | ||
| return False | ||
|
|
||
| should_skip = False | ||
| # We check for a boolean protectionForcedOff on the matching endpoints, allows users to disable scans on certain routes. | ||
| if protection_forced_off( | ||
| context.get_route_metadata(), thread_cache.get_endpoints() | ||
| ): | ||
| should_skip = True | ||
| # We check for Bypassed IPs : Allows users to let their DAST not be blocked by Zen | ||
| if thread_cache.is_bypassed_ip(context.remote_address): | ||
| should_skip = True | ||
|
|
||
| context.set_should_skip_attack_scan(should_skip) | ||
| context.set_as_current_context() | ||
|
|
||
| return should_skip | ||
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
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
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
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
Oops, something went wrong.
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.
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.
Comment restates the mechanics of the upcoming conditional instead of explaining the higher-level reason or intent.
Feedback
Post a comment with the following structure to provide feedback on this finding:
Aikido will process this feedback into learnings to give better review comments in the future.
More info