-
-
Notifications
You must be signed in to change notification settings - Fork 736
Reduce use of error level logging in pscan rules, tech detection, & retire #6645
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
Open
kingthorin
wants to merge
1
commit into
zaproxy:main
Choose a base branch
from
kingthorin:pscan-dont-log-at-error
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.
Open
Changes from all commits
Commits
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 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
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 |
---|---|---|
|
@@ -57,88 +57,82 @@ public class RetrievedFromCacheScanRule extends PluginPassiveScanner | |
@Override | ||
public void scanHttpResponseReceive(HttpMessage msg, int id, Source source) { | ||
|
||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a lot but it's because all the indentation changed. |
||
LOGGER.debug( | ||
"Checking URL {} to see if was served from a shared cache", | ||
msg.getRequestHeader().getURI()); | ||
|
||
// X-Cache: HIT | ||
// X-Cache: HIT from cache.kolich.local <-- was the data actually served from the | ||
// cache (subject to no-cache, expiry, etc.)? | ||
// (if X-Cache: HIT, it implies X-Cache-Lookup: HIT) | ||
// (and if X-Cache-Lookup: MISS, it implies X-Cache: MISS) | ||
// X-Cache-Lookup: HIT from cache.kolich.local:80 <-- was the data *available* in the | ||
// cache? (not whether it was actually served) | ||
|
||
// X-Cache: MISS | ||
// X-Cache: MISS from cache.kolich.local | ||
// X-Cache-Lookup: MISS from cache.kolich.local:80 | ||
|
||
// X-Cache HIT from proxy.domain.tld, MISS from proxy.local | ||
// X-Cache-Lookup HIT from proxy.domain.tld:3128, MISS from proxy.local:3128 | ||
|
||
List<String> xcacheHeaders = msg.getResponseHeader().getHeaderValues("X-Cache"); | ||
if (!xcacheHeaders.isEmpty()) { | ||
for (String xcacheHeader : xcacheHeaders) { | ||
for (String proxyServerDetails : xcacheHeader.split(",")) { | ||
// strip off any leading space for the second and subsequent proxies | ||
if (proxyServerDetails.startsWith(" ")) | ||
proxyServerDetails = proxyServerDetails.substring(1); | ||
LOGGER.trace("Proxy HIT/MISS details [{}]", proxyServerDetails); | ||
String[] proxyServerDetailsArray = proxyServerDetails.split(" ", 3); | ||
if (proxyServerDetailsArray.length >= 1) { | ||
String hitormiss = | ||
proxyServerDetailsArray[0].toUpperCase(); // HIT or MISS | ||
if (hitormiss.equals("HIT")) { | ||
// the response was served from cache, so raise it.. | ||
String evidence = proxyServerDetails; | ||
LOGGER.debug( | ||
"{} was served from a cache, due to presence of a 'HIT' in the 'X-Cache' response header", | ||
msg.getRequestHeader().getURI()); | ||
// could be from HTTP/1.0 or HTTP/1.1. We don't know which. | ||
buildAlert(evidence, false).raise(); | ||
return; | ||
} | ||
LOGGER.debug( | ||
"Checking URL {} to see if was served from a shared cache", | ||
msg.getRequestHeader().getURI()); | ||
|
||
// X-Cache: HIT | ||
// X-Cache: HIT from cache.kolich.local <-- was the data actually served from the | ||
// cache (subject to no-cache, expiry, etc.)? | ||
// (if X-Cache: HIT, it implies X-Cache-Lookup: HIT) | ||
// (and if X-Cache-Lookup: MISS, it implies X-Cache: MISS) | ||
// X-Cache-Lookup: HIT from cache.kolich.local:80 <-- was the data *available* in the | ||
// cache? (not whether it was actually served) | ||
|
||
// X-Cache: MISS | ||
// X-Cache: MISS from cache.kolich.local | ||
// X-Cache-Lookup: MISS from cache.kolich.local:80 | ||
|
||
// X-Cache HIT from proxy.domain.tld, MISS from proxy.local | ||
// X-Cache-Lookup HIT from proxy.domain.tld:3128, MISS from proxy.local:3128 | ||
|
||
List<String> xcacheHeaders = msg.getResponseHeader().getHeaderValues("X-Cache"); | ||
if (!xcacheHeaders.isEmpty()) { | ||
for (String xcacheHeader : xcacheHeaders) { | ||
for (String proxyServerDetails : xcacheHeader.split(",")) { | ||
// strip off any leading space for the second and subsequent proxies | ||
if (proxyServerDetails.startsWith(" ")) | ||
proxyServerDetails = proxyServerDetails.substring(1); | ||
LOGGER.trace("Proxy HIT/MISS details [{}]", proxyServerDetails); | ||
String[] proxyServerDetailsArray = proxyServerDetails.split(" ", 3); | ||
if (proxyServerDetailsArray.length >= 1) { | ||
String hitormiss = proxyServerDetailsArray[0].toUpperCase(); // HIT or MISS | ||
if (hitormiss.equals("HIT")) { | ||
// the response was served from cache, so raise it.. | ||
String evidence = proxyServerDetails; | ||
LOGGER.debug( | ||
"{} was served from a cache, due to presence of a 'HIT' in the 'X-Cache' response header", | ||
msg.getRequestHeader().getURI()); | ||
// could be from HTTP/1.0 or HTTP/1.1. We don't know which. | ||
buildAlert(evidence, false).raise(); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// The "Age" header (defined in RFC 7234) conveys the sender's estimate of the amount of | ||
// time since the response (or its revalidation) was generated at the origin server. | ||
// An HTTP/1.1 server that includes a cache MUST include an Age header field in every | ||
// response generated from its own cache. | ||
// i.e.: a valid "Age" header implies that the response was served from a cache | ||
// lets validate that it is actually a non-negative decimal integer, as mandated by RFC | ||
// 7234, however. | ||
// if there are multiple "Age" headers, just look for one valid value in the multiple | ||
// "Age" headers.. Not sure if this case is strictly valid with the spec, however. | ||
// Note: HTTP/1.0 caches do not implement "Age", so the absence of an "Age" header does | ||
// *not* imply that the response was served from the origin server, rather than a | ||
// cache.. | ||
List<String> ageHeaders = msg.getResponseHeader().getHeaderValues("Age"); | ||
if (!ageHeaders.isEmpty()) { | ||
for (String ageHeader : ageHeaders) { | ||
LOGGER.trace("Validating Age header value [{}]", ageHeader); | ||
Long ageAsLong = null; | ||
try { | ||
ageAsLong = Long.parseLong(ageHeader); | ||
} catch (NumberFormatException nfe) { | ||
// Ignore | ||
} | ||
if (ageAsLong != null && ageAsLong >= 0) { | ||
String evidence = "Age: " + ageHeader; | ||
LOGGER.debug( | ||
"{} was served from a HTTP/1.1 cache, due to presence of a valid (non-negative decimal integer) 'Age' response header value", | ||
msg.getRequestHeader().getURI()); | ||
buildAlert(evidence, true).raise(); | ||
return; | ||
} | ||
// The "Age" header (defined in RFC 7234) conveys the sender's estimate of the amount of | ||
// time since the response (or its revalidation) was generated at the origin server. | ||
// An HTTP/1.1 server that includes a cache MUST include an Age header field in every | ||
// response generated from its own cache. | ||
// i.e.: a valid "Age" header implies that the response was served from a cache | ||
// lets validate that it is actually a non-negative decimal integer, as mandated by RFC | ||
// 7234, however. | ||
// if there are multiple "Age" headers, just look for one valid value in the multiple | ||
// "Age" headers.. Not sure if this case is strictly valid with the spec, however. | ||
// Note: HTTP/1.0 caches do not implement "Age", so the absence of an "Age" header does | ||
// *not* imply that the response was served from the origin server, rather than a | ||
// cache.. | ||
List<String> ageHeaders = msg.getResponseHeader().getHeaderValues("Age"); | ||
if (!ageHeaders.isEmpty()) { | ||
for (String ageHeader : ageHeaders) { | ||
LOGGER.trace("Validating Age header value [{}]", ageHeader); | ||
Long ageAsLong = null; | ||
try { | ||
ageAsLong = Long.parseLong(ageHeader); | ||
} catch (NumberFormatException nfe) { | ||
// Ignore | ||
} | ||
if (ageAsLong != null && ageAsLong >= 0) { | ||
String evidence = "Age: " + ageHeader; | ||
LOGGER.debug( | ||
"{} was served from a HTTP/1.1 cache, due to presence of a valid (non-negative decimal integer) 'Age' response header value", | ||
msg.getRequestHeader().getURI()); | ||
buildAlert(evidence, true).raise(); | ||
return; | ||
} | ||
} | ||
|
||
} catch (Exception e) { | ||
LOGGER.error("An error occurred while checking if a URL was served from a cache", e); | ||
} | ||
} | ||
|
||
|
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.
This looks like a lot but it's because all the indentation changed.
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.
It is likely helpful to "Hide Whitespace" while reviewing this PR.