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

Added an OrchardCore Https module #1277

Merged
merged 6 commits into from
Dec 21, 2017
Merged

Conversation

petedavis
Copy link
Contributor

Added a module that provides a configuration wrapper around the MVC RequiresHttps filter.

@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Mvc.TagHelpers;
Copy link
Member

Choose a reason for hiding this comment

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

I assume this spilled in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used this tag helper in the settings editor view to disable an input field based on a condition. Maybe this should be put somewhere else, or there is another solution?

Copy link
Member

Choose a reason for hiding this comment

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

@{
  var disabled = Model.IsHttpsRequest ? "disabled" : (string) null;
}

<input disabled="@disabled"/>

Copy link
Member

Choose a reason for hiding this comment

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

Your opinion on that?


namespace OrchardCore.Https.Services
{
public class MvcOptionsHttpsConfiguration : IConfigureOptions<MvcOptions>
Copy link
Member

Choose a reason for hiding this comment

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

Maybe I missed this in the comments, but could we not just have a middleware do the redirection instead of relying on MVC?


public async Task<HttpsSettings> GetSettingsAsync()
{
var siteSettings = await _siteService.GetSiteSettingsAsync().ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

Remove ConfigureAwait, it's not necessary in ASP.NET Core.

@petedavis
Copy link
Contributor Author

@sebastienros now that I have change this. I think this should be refactored into a Rewrite module that the HTTPS module then depends on. That way other rewrite rules could be added, and a single RewriteOptions object can be configure by both modules.

<fieldset class="form-group" asp-validation-class-for="RequireHttps">
<div class="form-check">
<label class="form-check-label">
<input asp-for="RequireHttps" class="form-check-input" asp-is-disabled="@(!Model.IsHttpsRequest)" />
Copy link
Member

Choose a reason for hiding this comment

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

Why is it disabled when the current request is https ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I shot myself in the foot and clicked enable require https over http when https settings were incorrect. This is only disabled if the current request is NOT https.

Copy link
Member

Choose a reason for hiding this comment

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

So this way you can only enable it when the settings are correctly configured and working, meaning you are on HTTPS already? That's clever.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly

{
public override void Configure(IApplicationBuilder app, IRouteBuilder routes, IServiceProvider serviceProvider)
{
var rewriteOptions = new RewriteOptions();
Copy link
Member

Choose a reason for hiding this comment

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

That looks complicated, maybe you are right but I would have expected it to be simpler. Like just resolving the HttpsSettings here and registering the rewrite rule right there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I thought it would be just like MvcOptions and all the OpenId Options, where any registered IConfigureOptions would be invoked. Maybe a bug on ASP.NET Core Rewrite?

@sebastienros
Copy link
Member

That looks better now ... still some questions.

Have you seen this issue about adding more security features in OC? #854

Once this SSL one is done, we might be able to add the suggested ones as other features. That would make a nice Security module.

<ProjectReference Include="..\..\OrchardCore\OrchardCore.Entities.DisplayManagement\OrchardCore.Entities.DisplayManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Environment.Navigation\OrchardCore.Environment.Navigation.csproj" />
</ItemGroup>

Copy link
Member

Choose a reason for hiding this comment

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

@petedavis just for infos, you need to reference OrchardCore.Module.Targets.csproj to make it working when the module will be packed and referenced as a package.

Copy link
Member

Choose a reason for hiding this comment

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

Done

@sebastienros
Copy link
Member

FYI, there will be a middleware for that very soon. It will simplify the code and also add support for HsTs
https://github.com/aspnet/BasicMiddleware/pull/264/files

@petedavis
Copy link
Contributor Author

@sebastienros Should I rename the module to be OrchardCore.Security, and make this the place to add security features mentioned in #854?

@sebastienros sebastienros merged commit e2af89a into OrchardCMS:dev Dec 21, 2017
@sebastienros sebastienros mentioned this pull request Jan 10, 2018
@petedavis petedavis deleted the ssl branch February 24, 2019 06:19
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.

5 participants