Example 16: Security

Overview

In this example we cover various aspects of security both static code checks that are automatic done during build and techniques used to dynamically secure the UI. Dynamic security testing is not covered here but the extension framework does support it.

You can find the code for the example in our GitHub repository.

Important: Wincom offers these services but cannot be held responsible for the effectiveness of otherwise of the security provided by this code.

Implementation

Reporting

There are three reports generated during build

Security Report

On every build a test report will be generated

The report will also be appended with any other PDF documentation that is in the extension security area

image-20231203144550426iate

The security report contains the following sections:

Securing for XSS Vulnerabilities

Coding

An XSS vulnerability is a common issue that needs to be protected against

This example use the library wt-security-commons that in turn uses com.googlecode.owasp-java-html-sanitizer

image-20240104152828440

Securing a UI Page

Security is in most cases not required for the UI, as Windchill itself manages security and access control to data. However, if we do wish to allow access only to a certain group of users e.g admins, we can use the WEX Framework's wt-security-commons code to do this:

import com.wincomplm.wex.security.commons.impl.WexSecurePage;

@WexMethod(name = "securePage", description = "A simple security example")
    public void securePage() throws Exception { 
        if (!WexAdminCheckAccess.instance.isSiteOrBusinessAdmin()) {
            httpresponse.sendError(403, "User is not an administrator.");
        }       
     }//securePage

Also, try to access the URL directly as a non-admin user:

http://{your_host}/Windchill/ptc1/com/wincomplm/wex/example/ui/edkHelloWorld

You will get the error below:

1622398937830

This error gives little information, which is intentional as security-related errors should disclose as little information as possible. However, the MS logs clearly show the cause:

wt.util.WTException: User must be site administrator to access page
...
 com.wincomplm.wex.example.ui.impl.ui.methods.ExampleUIMethods.securePage(ExampleUIMethods.java:24)

Rate limiting

On certain operations it is important to rate limit to avoid an exhausting of resources e.g. disk space

This can be coded using the limiter

static WexPerUserRateLimiter limiter = WexPerUserRateLimiter.newPerUserRateLimiter(10, TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES));

@WexMethod(name = "get-example-data", description = "Get example")
public void getExampleData(HttpServletRequest httprequestUnsafe, HttpServletResponse httpresponse) throws Exception { 

    limiter.checkException();

}//getExampleData

Security Approval and Exclusions

The extension can implement the following in the security area

UI and JUnit implementation

The user guide give access to the following pages

Hello World

Which is an admin only page and will be rejected for other users.

XSS Test Page

XSS Test)

This test will provoke an XSS as the payload will be executed

To ensure the page is not vulnerable to XSS

python xsstrike.py -u http://beauty.wincomplm.com/Windchill/netmarkets/jsp/com/wincomplm/wex/example/security/xssTest.jsp?id=test --headers "authorization: Basic d2NhZG1pbjp3Y2FkbWlu"

an automated tool should be used, such as XSStrike

image-20240904141651920

Junit Testing

Runs all the Junit tests