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

DOC Update secure coding documentation to reflect best practices #696

Merged

Conversation

GuySartorelli
Copy link
Member

Two commits here - if you squash, make sure the commit message is broad enough to encompass both of them.

Commit 1: Update best practice for setting CanonicalURLMiddleware.ForceSSL

Commit 2: Backport of #692 minus the bit about the warning. The beta has been delayed and it's possible the blog post will be live before we swap over the source of documentation.

Issue

`_config.php` used to be very common for configuration, but more and
more we're preferring YAML configuration. I've never seen a project use
the php API for this, since it doesn't allow as much configuration as
the YAML API does.
Comment on lines +803 to +813
### Using SSL in database connections

In some circumstances, like connecting to a database on a remote host for example, you may wish to enable SSL encryption to ensure the protection of sensitive information and database access credentials.
You can configure that by setting the following environment variables:

| Name | Description |
| ---- | ----------- |
| `SS_DATABASE_SSL_KEY` | Absolute path to SSL key file (optional - but if set, `SS_DATABASE_SSL_CERT` must also be set) |
| `SS_DATABASE_SSL_CERT` | Absolute path to SSL certificate file (optional - but if set, `SS_DATABASE_SSL_KEY` must also be set) |
| `SS_DATABASE_SSL_CA` | Absolute path to SSL Certificate Authority bundle file (optional) |
| `SS_DATABASE_SSL_CIPHER` | Custom SSL cipher for database connections (optional) |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to move this to be adjacent to the other bit of docs talking about TLS.

| `SS_DATABASE_SSL_CA` | Absolute path to SSL Certificate Authority bundle file (optional) |
| `SS_DATABASE_SSL_CIPHER` | Custom SSL cipher for database connections (optional) |

## Secure sessions and cookies
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to separate this into its own section - secure cookies and TLS are sort-of related but I don't think enough so to join them together like that.


if (!Director::isDev()) {
Director::forceSSL();
Copy link
Member Author

@GuySartorelli GuySartorelli Feb 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API does exist but it's a lot less powerful than configuring via YAML because

  • there are a lot of options on CanonicalURLMiddleware that can't be set via director (even the rest of this old docs has to instantiate a singleton of the middleware to set something)
  • you ideally want everything configuring this in the same place - so if you have to set some of it in YAML and then some here, that's hard to notice and may cause problems
  • I'd expect basically every project that configures CanonicalURLMiddleware uses YAML, following CWP's example.

Basically there's no good reason to be setting this in _config.php

@emteknetnz emteknetnz merged commit 6f37e3e into silverstripe:5.3 Feb 16, 2025
4 checks passed
@emteknetnz emteknetnz deleted the pulls/5.3/secure-coding branch February 16, 2025 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants