I'm not sure whether to consider this a bug report or a feature request, but here it is: Currently, for each domain configured, you may specify whether to use http or https, and if a domain source is configured, URLs throughout that site (including form actions and so forth) use that protocol.

This doesn't entirely support my configuration. We have a public domain for our public website that uses http in most cases, but enforces the use of https for certain paths (the user login page and the admin pages) to protect this data.

Unfortunately, configuring the URL scheme for this domain to be http:// and simply letting our rewrite rules redirect to https:// does not work. Since the form actions are all set to http:// with this configuration, form submissions from https:// fail.

The solution would be one of the following:

  1. Allow both http and https on a given domain, and write URLs to one or the other depending on the request or base URL (using the dynamic base URL in #633726: Include instructions for altering $base_url), or
  2. Allow certain paths to be configured to use a separate protocol from the domain's main protocol. (This solution would be even better because it would reduce the number of rewrite rules needed to support such a configuration.)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agentrickard’s picture

Version: 6.x-2.4 » 7.x-2.x-dev

It's a feature request. You may have to handle this yourself for now in a hook_form_alter().

xjm’s picture

Thanks for the quick followup. Which module's hook_form_alter() would I need to modify, domain.module or domain_source.module? If I get it working, I can submit a patch.

Edit: just to clarify, I looked at both functions, but I couldn't figure out why the form actions were all ending up as http for all forms; domain_source only seemed to be acting on the node form and "domain_content_form."

Edit 2: Never mind, I think I found it; I was looking at a hook_form_FORM_ID_alter() before. Looks like domain_form_alter() is the function I'd need to change, the if ($seo) part?

xjm’s picture

Also, I think #368805: Domain Access with Subdomains and SSL was caused by the same base issue.

agentrickard’s picture

Don't alter my function. Write your own module, something like domain_ssl. And use domain_ssl_form_alter() to change the $form['#action'].

xjm’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev
Status: Active » Needs work
FileSize
1.2 KB

Here's the beginnings of such a module, in case anyone else is interested. (It's for 6.x, since I don't have any production 7.x sites, but it'd be straightforward to port). Edit: the files with names ending in ~ are just backups I forgot to be delete and can be removed.

All it does for the moment is fix the form action to accommodate both protocols for a domain, regardless of how the protocol gets set. It would be more useful if it implemented hook_domain_source_alter() (I think?) to allow per-path protocol rules (e.g., use https for user/*, admin/* even if the domain is configured for http).

Thanks for your help. :)

hefox’s picture

Subscribe. Will look into it soon, as I need it also.

Would this be a separate (sub)module?

If so, could make a d.o project so those interested could test it and file patches, etc.

xjm’s picture

I suppose that depends on whether agentrickard thinks it would be worth including with the main module. If not, I'd be glad to help maintain it as well.

butler360’s picture

Subscribing.

agentrickard’s picture

For D7, I have the following module already on my plate, but nothing for D6. Decide based on that.

DOMAIN PATH

-- Allows the registration of arbitrary Drupal paths (either aliases or canonical paths) with a given Domain.
-- Will allow rewrites of links to that path to follow the domain rewrite rules currently used by nodes.

It would be pretty easy, I think, to add an HTTP / HTTPS toggle to these settings.

I just looked through the D6 code to confirm, using either hook_domain_source_alter() or hook_domain_source_path_alter(), you can toggle the HTTP / HTTPS element of a node or Drupal path without any changes to the core module. You just have to alter the 'path' element of the $domain array by reference.

So, something like:

function mymodule_domain_source_path_alter(&$source, $path) {
  Always write admin paths to HTTPS.
  if ($path != 'admin') {
    return;
  }
  $source['path'] = str_replace('http://', 'https://', $source['path']);
}

This part is dead simple; the harder part is a UI to control these settings. A separate module is the only option for D6.

There will, of course, be a performance hit here, especially if you have to do a database lookup inside this function. Might be best to cache all the rewrite rules from a single query.

jessefulton’s picture

+1

agentrickard’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Lloyd’s picture

I installed the SSL module per #5. It works but with a hitch. I'm now getting the mixed content warning in IE and FF.

scarr’s picture

Subscribing - would be great to have, and I'm willing to test

xjm’s picture

Since this is in development for D7 but not D6, I'm going to open a new project for D6, starting with the module from #5. I'll post the link here once I get it in CVS.

Druid’s picture

How does a shopping cart (e.g., Ubercart) handle something like this? Normally you would want the catalog (public material) to be http, but admin and sensitive customer information (name, address, phone, payment details, etc.) to be https. Does Drupal really require the whole site to be one or the other, but not a mixture of http and https? That would be horrible! Anyway, if Ubercart permits a mix, perhaps you could get some ideas poking around in its code?

xjm’s picture

Re: #15 -- To clarify, the issue/project is specific to the Domain Access module. Drupal by itself is agnostic in that regard; it's up to the webserver to control that functionality. I've used mixed http and https with Drupal for years and it's worked fine; it's just that the main Domain Access module does not support that configuration at present. Thence the companion module.

xjm’s picture

Project page:
http://drupal.org/project/domain_ssl

The module is now available in CVS, and (edit) the development snapshot is now available for download.

agentrickard’s picture

Nice, but looking at the code, I wonder if we should just patch the main module. This is the part that interests me:

    // Protocol of current request.
    $req = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
      ? 'https' : 'http';

    // If the protocol doesn't match the current page's protocol, fix it.
    if (($action['scheme'] != $req) && ($action['host'] == $domain['subdomain'])) {
      $form['#action'] =  $req .'://'. $action['host'] . $action['path'] . $action['query'];
    }

We may want to put that into hook_domainload(), in fact, to dynamically force HTTPS in cases where other modules use the protocol.

Druid’s picture

On some servers, $_SERVER['HTTPS'] may have a value of '1' instead of 'on'. You may want to check for that.

agentrickard’s picture

Yes, I second that, I'm used to a TRUE/FALSE response. There are actually places in the code where I do this:

  if (!empty($_SERVER['HTTPS'])) {
    $scheme = 'https';
  }

See domain_set_primary_domain().

This is the proper check, see http://php.net/manual/en/reserved.variables.server.php

 'HTTPS'
    Set to a non-empty value if the script was queried through the HTTPS protocol.

        Note: Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol. 

If the value is ever set to the string 'off', this is a server-level implementation error.

xjm’s picture

Ah... well.

Would you backport it to 6.x if you patched for #18?

I actually based the protocol check on http://drupal.org/node/217710#comment-718517 (also agentrickard's post), which is what I use in my settings.php. I can patch my module to use !empty(). However, am I to undertand from the pulled quote that this may fail on IIS? If so, maybe: if (!empty($_SERVER['HTTPS'] && ($_SERVER['HTTPS'] != 'off'))

xjm’s picture

Also, I've seen talk of putting something to use https for sensitive form actions in core, but looks like it didn't make it into D7: #616744: Add a UI for if the site supports https

agentrickard’s picture

The old code sample is, well, old (from 2008). And replaced by better understanding of the PHP docs.

I would patch this directly in 7.x and then backport immediately, yes.

wesleymusgrove’s picture

@agentrickard Has the code from the D6 Domain SSL module (to allow both http and https on a given domain) been patched into D7 Domain Access core or contrib module? Or is there still a need to implement this functionality in a custom D7 module?

Thanks

agentrickard’s picture

Still needs work (either a patch or a module) for D7.

codewatson’s picture

Where in the module would we need to look to patch this for D7? Or what needs to be updated in the Domain SSL module?

codewatson’s picture

Oh it appears the D6 version of the Domain SSL module can be updated just by changing the version numbers in the info file, and it appears to work as expected so far... Are there any problems that I might not foresee by doing this?

deggertsen’s picture

Issue summary: View changes

I need this on a D7 site, but I don't quite understand the above well enough to implement it. Can someone summarize instructions on how to get this working?

sk2013’s picture

+1

dalin’s picture

This might be a little late to be useful to anyone, but here's a hack that bypasses Domain module from trying to enforce a scheme.