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

pscanrules: add examples alerts to Insecure JSF ViewState #5688

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addOns/pscanrules/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased
### Changed
kingthorin marked this conversation as resolved.
Show resolved Hide resolved
- Rename Mac OSX salted SHA-1 in the Hash Disclosure scan rule to "Salted SHA-1", reduce the associated alerts to Low risk and Low confidence, to align with other SHA related patterns it will only be evaluated a Low Threshold. (Note such matches may indicate leaks related but not limited to: MacOS X, Oracle, Tiger-192, Haval-192) (Issue 8624).
- The Insecure JSF ViewState now includes example alert functionality for documentation generation purposes (Issue 6119).

## [60] - 2024-09-02
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void scanHttpResponseReceive(HttpMessage msg, int id, Source source) {
// If the ViewState is not secured cryptographic
// protections then raise an alert.
if (!isViewStateSecure(val, msg.getRequestBody().getCharset())) {
raiseAlert(msg, id, src);
createAlert(src).setMessage(msg).raise();
}
}
}
Expand Down Expand Up @@ -202,17 +202,16 @@ private boolean isRawViewStateSecure(String viewState) {
return true;
}

private void raiseAlert(HttpMessage msg, int id, String viewState) {
newAlert()
private AlertBuilder createAlert(String viewState) {
return newAlert()
.setRisk(getRisk())
.setConfidence(Alert.CONFIDENCE_LOW)
.setDescription(getDescription())
.setOtherInfo(Constant.messages.getString(MESSAGE_PREFIX + "extrainfo", viewState))
.setSolution(getSolution())
.setReference(getReference())
.setCweId(getCweId())
.setWascId(getWascId())
.raise();
.setWascId(getWascId());
}

// jsf server side implementation in com.sun.faces.renderkit.ServerSideStateHelper
Expand Down Expand Up @@ -254,4 +253,11 @@ public int getCweId() {
public int getWascId() {
return 14; // WASC Id - Server Misconfiguration
}

@Override
public List<Alert> getExampleAlerts() {
return List.of(
createAlert("<input type=\"hidden\" id=\"javax.faces.viewstate\" value=\"1231\"")
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -270,4 +271,18 @@ private void setTextHtmlResponseHeader(HttpMessage msg) throws HttpMalformedHead
+ "Server: Apache-Coyote/1.1\r\n"
+ "Content-Type: text/html;charset=UTF-8\r\n");
}

@Test
void shouldHaveExpectedExampleAlert() {
// Given / When
List<Alert> alerts = rule.getExampleAlerts();
// Then
assertThat(alerts.size(), is(equalTo(1)));
}

@Test
@Override
public void shouldHaveValidReferences() {
super.shouldHaveValidReferences();
}
}