> For the complete documentation index, see [llms.txt](https://fsdhgroup.gitbook.io/fsdh-developer-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fsdhgroup.gitbook.io/fsdh-developer-documentation/going-live/best-practices.md).

# Best Practices

Suggested security practices

### Security Recommendations

#### API Management&#x20;

Verify that your app meets these requirements for managing your API Keys&#x20;

* Client ID & Client secret should **not** be hard coded in the codebase.&#x20;
* API calls requiring your Bearer Token should **never** be initiated from a client (browser/mobile app). It should be done from the backend/server part of the application&#x20;
* Client ID & Client secret **should** be stored in environmental variables or secrets manager.&#x20;

#### Authentication

* Ensure a **strong** password policy is enforced e.g. minimum of 8 alphanumeric characters, an upper case, a special character&#x20;
* Input validation is in place during login&#x20;
* Implement controls against brute-force - account lockouts, second-factor authentication and so on.&#x20;
* Store database credentials securely using secrets manager preferably.&#x20;

#### Cookie Management

* Ensure all app session cookies have the following attributes set&#x20;
* Secure&#x20;
* HTTP only&#x20;
* Upon the user logging out, the user’s session must be terminated server-side, and any client-side session tokens should be cleared and not cached on the user’s machine&#x20;
* Any session tokens must be stored within session cookies and transported only within HTTP cookie headers&#x20;

#### Session Management

* Session timeouts should be configured on the server&#x20;
* Session duration should be limited to a maximum of 10 hours, after which the user must be required to authenticate again&#x20;
* Implement an idle session timeout&#x20;
* Deny concurrent sessions&#x20;
* Ensure session tokens are generated using a Random Number Generator (RNG) cryptographic provider so it cannot be easily predictable.&#x20;

#### Session Termination

* A clearly accessible button must exist which allows users to log out of the application, which in turn ends the session on the server&#x20;
* Application sessions must be invalidated at the server-side&#x20;
* Log out function must effectively destroy all session tokens and render them useless.&#x20;

#### Handling Sensitive information

* Securely exchange encryption keys - Ensure key exchanges are performed over a secure channel (TLS 1.2 and TLS 1.3)&#x20;
* Limit the use and storage of sensitive data - Ensure sensitive data are not unnecessarily transported and stored. Where possible use abstract identifiers to reduce data exposure risk.&#x20;
* Encryption of sensitive data at rest&#x20;

#### Error Handling and Accountability

* Ensure to log all privileged changes&#x20;
* Log all user (customer) and administrative activities&#x20;
* Log all access to sensitive data&#x20;
* When encountered with an unhandled exception, display generic messages to the end-user. Do not reveal details about the internal state of your application eg. database errors, app server errors etc&#x20;
* Store logs securely and follow international standards for log retention&#x20;

#### Input and Output Forms

* All input (user and service) must be validated only on the server-side in addition to any client-side validation to permit only the characters required and field length necessary&#x20;
* All output back should be encoded&#x20;
* With proper input validation and output encoding, applications should not be susceptible to cross-site scripting, either stored or reflected. This includes all headers, cookies, query strings, form fields and hidden fields&#x20;
* Create a whitelist of acceptable characters to be used by the application&#x20;
* Ensure proper validation is done for files that are uploaded&#x20;
* Use parameterized SQL queries&#x20;

#### Application Server

* Ensure caching has been disabled on all SSL pages and all pages that contain sensitive data by using value no-cache and no-store instead of private in the Cache-Control header&#x20;
* All OS, web server and app server security patches are up to date at this time, and new patches are applied in a commercially reasonable time frame after they are made available by the hardware and software vendors&#x20;
* SSL must be configured to support only TLS version 1.2 or higher.&#x20;
* HTTPS is enforced on all pages and endpoints of your application&#x20;
* The app web server must be configured to disable the TRACE and other HTTP methods if not being used&#x20;

#### Vulnerability and Security Assessment&#x20;

Ensure your application is secured against this non-exhaustive list&#x20;

* Cross-Site Request Forgery&#x20;
* Cross-Site Scripting reflected and stored cross-site scripting&#x20;
* SQL Injection&#x20;
* XML Injection&#x20;
