-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2603 from mercedes-benz/feature-2555-zap-wrapper-…
…handle-includes-excludes-wildcards Feature 2555 zap wrapper handle includes excludes wildcards
- Loading branch information
Showing
13 changed files
with
154 additions
and
106 deletions.
There are no files selected for viewing
This file contains 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 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 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
61 changes: 33 additions & 28 deletions
61
...src/main/java/com/mercedesbenz/sechub/zapwrapper/helper/IncludeExcludeToZapURLHelper.java
This file contains 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 |
---|---|---|
@@ -1,61 +1,66 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.zapwrapper.helper; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Collections; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import com.mercedesbenz.sechub.commons.model.SecHubMessage; | ||
import com.mercedesbenz.sechub.commons.model.SecHubMessageType; | ||
import com.mercedesbenz.sechub.zapwrapper.util.UrlUtil; | ||
|
||
public class IncludeExcludeToZapURLHelper { | ||
private UrlUtil urlUtil = new UrlUtil(); | ||
|
||
/** | ||
* Combine the targetUrl with all list of subSites.<br> | ||
* Combine the targetUrl with the given list of subSites.<br> | ||
* <br> | ||
* E.g. for the targetUrl http://localhost:8000 and the sub sites ["/api/v1/", | ||
* "admin/profile"], results in ["http://localhost:8000/api/v1", | ||
* "http://localhost:8000/admin/profile"]. | ||
* "<*>admin/<*>", "api/users/"], results in ["http://localhost:8000/api/v1", | ||
* "http://localhost:8000/.*admin/.*", "http://localhost:8000/.*api/users/.*"]. | ||
* | ||
* @param urlType | ||
* @param targetUrl | ||
* @param targetUrl, must never be <code>null</code> | ||
* @param subSites | ||
* @param userMessages | ||
* @return a list of full URLs | ||
* @return an unmodifiable list of full URLs, or an empty list if subSites was | ||
* empty. | ||
*/ | ||
public List<URL> createListOfUrls(ZapURLType urlType, URL targetUrl, List<String> subSites, List<SecHubMessage> userMessages) { | ||
public List<String> createListOfUrls(URL targetUrl, List<String> subSites) { | ||
Objects.requireNonNull(targetUrl); | ||
if (subSites == null) { | ||
return new LinkedList<URL>(); | ||
return Collections.emptyList(); | ||
} | ||
|
||
String targetUrlAsString = targetUrl.toString(); | ||
List<URL> listOfUrls = new LinkedList<>(); | ||
List<String> listOfUrls = new LinkedList<>(); | ||
for (String subSite : subSites) { | ||
StringBuilder urlBuilder = new StringBuilder(); | ||
|
||
// append the base target url first | ||
if (targetUrlAsString.endsWith("/")) { | ||
urlBuilder.append(targetUrlAsString.substring(0, targetUrlAsString.length() - 1)); | ||
urlBuilder.append(targetUrlAsString); | ||
} else { | ||
urlBuilder.append(targetUrlAsString); | ||
} | ||
|
||
if (!subSite.startsWith("/")) { | ||
urlBuilder.append("/"); | ||
} | ||
if (subSite.endsWith("/")) { | ||
urlBuilder.append(subSite.substring(0, subSite.length() - 1)); | ||
|
||
// replace wildcards with patterns | ||
String replacedSubsite = urlUtil.replaceWebScanWildCardsWithRegexInString(subSite); | ||
|
||
// create include/exclude URL pattern | ||
if (replacedSubsite.startsWith("/")) { | ||
urlBuilder.append(replacedSubsite.substring(1)); | ||
} else { | ||
urlBuilder.append(subSite); | ||
} | ||
try { | ||
listOfUrls.add(new URL(urlBuilder.toString())); | ||
} catch (MalformedURLException e) { | ||
userMessages.add(new SecHubMessage(SecHubMessageType.ERROR, "The specified " + urlType.getId() + " " + subSite | ||
+ " combined with the target URL: " + targetUrl + " formed the invalid URL: " + urlBuilder.toString())); | ||
if (!replacedSubsite.startsWith(UrlUtil.REGEX_PATTERN_WILDCARD_STRING)) { | ||
urlBuilder.append(UrlUtil.REGEX_PATTERN_WILDCARD_STRING); | ||
} | ||
urlBuilder.append(replacedSubsite); | ||
|
||
if (!replacedSubsite.endsWith(UrlUtil.REGEX_PATTERN_WILDCARD_STRING)) { | ||
urlBuilder.append(UrlUtil.REGEX_PATTERN_WILDCARD_STRING); | ||
} | ||
} | ||
listOfUrls.add(urlBuilder.toString()); | ||
} | ||
return listOfUrls; | ||
return Collections.unmodifiableList(listOfUrls); | ||
} | ||
|
||
} |
This file contains 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 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 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 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.