As part of making Drupal more visible, and its spread more measurable, this patch adds a META GENERATOR in the generated HTML, and a special HTTP header as well.

This behavior is on by default, with only the major number, and can be turned off under Administer -> Site information, or include the minor version (if you are an exhibitionist), or just "Drupal".

Before someone jumps in and shoots this down, for security reasons, or whatever, consider the following:

CMSes do it

Xaray adds the following: <meta name="Generator" content="Xaraya" />

Joomla adds the following: <meta name="Generator" content="Joomla! - Copyright (C) 2005 - 2006 Open Source Matters. All rights reserved." />

And WordPress adds the following. <meta name="generator" content="WordPress 2.5.1" />. Note the minor version, as well as patch level! And better yet, note this comment after it: <!-- Please leave for stats -->. Not sure what stats or how, but there you have it.

For the curious, this is the issue that added this feature not too long ago in Aug 2007.

Apache does it

Moreover, look at your web server headers, and see what they reveal: perhaps more than Drupal will ever reveal. Here are some examples (hint, check ServerTokens Full in your Apache configuration):

Server: Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8b mod_bwlimited/1.4

Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.1 with Suhosin-Patch

PHP does it

Example: X-Powered-By: PHP/5.2.5-pl1-gentoo

Check the expose_php settings in your php.ini file!

Benefits to Drupal

1. Give Drupal visibility for those who are interested (e.g. evaluators, management consultants, technology watchers, ...etc).

2. Give Netcraft and others the means to answer the question: "how many sites are running Drupal and what versions"? They do that for Apache/IIS/others in their web servers survey, and it would only be a matter of time before they do it for CMSes. We can even contact them and give them this hint once Drupal 7 (with this patch) is released.

3. Reduce the amount of guess work needed for support (whether by the community in the issue queue or the forums, or by Drupal shops).

4. Provides an authoritative way of "fingerprinting" Drupal sites without having to go through hoops and various techniques.

But this is a security risk, you may argue. Well, if it is, then it is security by obscurity. All the Linux distros, Apache, PHP and Linux distros ship with these settings on by default. If it is good for them, it is good for us.

Comments

keith.smith’s picture

Status: Active » Needs work

Not a bad idea, lots of other systems do it, and it would increase exposure (a long previous issue about hiding version and fingerprinting data as a security precaution notwithstanding).

There are some minor code style issues -- comments that need to be full sentences complete with periods, and I'm not convinced, to use the classic example, that my mother would understand the form description "Choose whether your HTML should show a META tag with the GENERATOR as Drupal. You can choose whether to display the major version (e.g. "Drupal 7"), the major and minor versions (e.g. "Drupal 7.2"), no version (only "Drupal"), or nothing at all." I think descriptions like this should not only point out that you can choose -- that part is obvious -- but perhaps give some advice about why one may wish to do so.

In terms of advertising for Drupal, this is roughly equivalent to adding the Drupal banner block, which I also thought was a good move.

And there is a patch, so I'm going for code needs work.

dries’s picture

Sounds useful to me.

I'm not sure I should expose this level of configuration to the user though. It seems to me like 99.9% of the users wouldn't care about this to begin with. I'd simply make it a theme thing to take it out, and hard-code a specific format. Let's make Drupal easier to use. The last thing my dad wants to do is learn about the generator-tag.

kbahey’s picture

Status: Needs work » Needs review

Here is another CMS that does it.

<meta name="generator" content="Movable Type Publishing Platform 4.01" />

@Dries, would this be better as a hidden variable (I mean commented out) in settings.php without a UI?

@keith.smith, if Dries approves that the UI is dumped, then most of your comments would be addressed.

dries’s picture

I'm OK with a variable, but personally, I think it is overkill still. It can be removed at the theme-level.

Let's also make sure to write a test for this.

kbahey’s picture

StatusFileSize
new3.12 KB

@Dries

Unless I am missing something obvious, I don't see how a theme can override drupal_set_html_head() and drupal_set_header(). That is why it is a variable.

Anyways, the attached patch does away with the user interface entirely. There is a variable in settings.php that is commented out.

I can roll the patch for D6 and even D5 as well if this gets accepted. Just set it to needs porting and I will do it.

dries’s picture

I still think that adding a setting for this is overkill, but I'll let others comment on this.

kbahey’s picture

If it is programmatically overridable, I agree there is no need for a variable. But I don't know of a way to do that with the two functions I mentioned. I am using those two functions because it is a theme independent way of adding the meta generator, and the only way of adding HTTP headers.

That is why I have the variable.

Crell’s picture

I am curious why #5 uses node_init() to add the generator text. Wouldn't system_init() make more sense? It doesn't really have anything to do with nodes.

I don't have any problem with the concept of the patch itself.

greggles’s picture

Status: Needs review » Needs work

CNW: Extra newline above function node_last_changed and I agree with Crell that this should be in system rather than node.

In general, I'm +1 for the feature, but feel that the comment block in settings.php is overkill.

The two other variables without a UI in core are dev_query and allow_insecure_uploads. These have basically no documentation within core itself. If this new feature were documented in a handbook page that would seem reasonable to me.

For a themeable solution drupal_meta_generator can call a theme function, right? That would allow overriding at the theme layer.

+  drupal_set_header(theme('generator_header', $version));
+  drupal_set_html_head(theme('generator_head($version));

Then those two theme_ functions return the properly formatted string. It also fits with the goal of no hard-coded html in core.

kbahey’s picture

Assigned: Unassigned » kbahey
Status: Needs work » Needs review
StatusFileSize
new1.8 KB

@Crell and @greggles

Thanks for the comments.

Attached is a smaller patch, and only affects one file.

Verified working even :-)

Please review ...

Susurrus’s picture

Why is it

list($major,) = explode('.', VERSION);
$version = $major;

instead of

list($version,) = explode('.', VERSION);

?

kbahey’s picture

StatusFileSize
new1.86 KB

No good reason. Just left over code from the earlier patches.

New patch attached.

cburschka’s picture

Installed the patch, but I see no HTTP header nor meta tag. Do I need to clear a cache or reinstall the site?

Edit: Gah, sorry, I missed the fact that this is done with theme functions. Theme registry rebuilt.

cburschka’s picture

StatusFileSize
new1.86 KB

It's functional and adheres to code style. There is one typo in hook_theme, namely 'arguments' => array('version' => NULL,), where the last comma should be outside the parenthesis.

This patch fixes the typo.

dries’s picture

Status: Needs review » Needs work

I've committed this to CVS HEAD. I'm marking it 'code needs work' because it would be good to have a test case for this.

Thanks all.

xmacinfo’s picture

If we can turn this thing off, I'm OK with "Generator".

It's not because a few CMS advertise themselves in the HTTP headers that Drupal should do the same. Pulling security issues under the rug won't help either. With generator on, it will be a lot easier for hacker to target security holes with much more efficiency.

So, ultimatly, the decision should be made at the site admin level. We must not forget that there are a lot of corporate users using Drupal for extranet and they would want to make sure this is turned off.

kbahey’s picture

@xmacinfo

In addition to other CMSes, the same argument can be said for Debian, RedHat, Ubuntu, Gentoo, Apache, PHP, ...etc. They expose info about versions, installed modules, ...etc. So why is it that they do this without any concern about security? Are they dumb or oblivious to the risks?

Since this is a theme function, it can be overridden like any other theme function with a few lines of code.

kbahey’s picture

Status: Needs work » Needs review
StatusFileSize
new2.09 KB

This is the same patch for Drupal 6, in case Dries/Gabor decide to add it to a future 6.3.

kbahey’s picture

StatusFileSize
new924 bytes

This is the test for HEAD for this patch.

It tests only the HTML part, and it works. I don't know of a way to test HTTP Headers.

kbahey’s picture

StatusFileSize
new1.06 KB

This is a better test that is version independent, and has better title, group, ...etc.

keith.smith’s picture

Status: Needs review » Needs work

Very cool. The only things I see are periods at the ends of a few comments at the ends of periods and consistent use of either "meta", "Meta", (or presumably, "META").

kbahey’s picture

Status: Needs work » Needs review
StatusFileSize
new1.07 KB

Updated the patch per comments.

dries’s picture

Status: Needs review » Fixed

Committed patch #22 to CVS HEAD. Thanks kbahey.

kbahey’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Patch (to be ported)

Setting this "to be ported" for Drupal 6, in case Dries/Goba think it is a good idea (see #18).

It would help with the visibility of Drupal 6, which now has a longer time span after the extension of the code freeze.

xmacinfo’s picture

I’m testing this new feature. Now each page have:

<meta name="Generator" content="Drupal 7 (http://drupal.org)" />

Since this is a theme function, it can be overridden like any other theme function with a few lines of code.

Can you give me an example of the few lines of code I would need to either remove the Generator completly or
be more specific in the version number? Would we be able to display "Drupal 7.0-dev" instead of the major version number?

xmacinfo’s picture

Overriding the HTML meta works perfectly. Please ignore previous request.

catch’s picture

Title: Add fingerprinting META Generator and HTTP headers for Drupal » Regression: Poll tests broken (was Add fingerprinting META Generator and HTTP headers for Drupal)
Version: 6.x-dev » 7.x-dev
Category: feature » bug
Priority: Normal » Critical
Status: Patch (to be ported) » Needs work

This broke poll.test

Marking #276200 - "poll tests don't pass" postponed until this is resolved.

edit: I doubled checked, and just to confirm, the poll theming is actually broken, not just the test.

cburschka’s picture

Version: 7.x-dev » 6.x-dev
Category: bug » feature
Priority: Critical » Normal
Status: Needs work » Patch (to be ported)

... I see that even with unit testing, the poll module still retains its status as the catcher of obscure regressions!

However, I must come to the defense of this issue. It is innocent of the crime. Compare:

The output of the theme call:

<span id="thmr_34" class="thmr_call">

<div class="text">simpletest_acn6</div>
<div class="bar">
  <div style="width: 0%;" class="foreground"></div>
</div>
<div class="percent">
  0% (0 votes)
</div>
</span>

The page that was returned to CURL:

<div class="text">simpletest_P1sy</div>
<div class="bar">
  <div style="width: 0%;" class="foreground"></div>
</div>
<div class="percent">
  0% (0 votes)
</div>

<div class="text">simpletest_iw8Q</div>
<div class="bar">
  <div style="width: 0%;" class="foreground"></div>
</div>
<div class="percent">
  0% (0 votes)
</div>

<div class="text">simpletest_acn6</div>
<div class="bar">
  <div style="width: 0%;" class="foreground"></div>
</div>
<div class="percent">
  0% (0 votes)
</div>
  <div class="total">
    Total votes: 0  </div>
  </div>
  </div>

I accuse devel_themer, with the span-element, in the theming layer!

cburschka’s picture

Title: Regression: Poll tests broken (was Add fingerprinting META Generator and HTTP headers for Drupal) » Add fingerprinting META Generator and HTTP headers for Drupal

I can confirm that after disabling devel_themer, poll.test passes. I'll open a new issue.

catch’s picture

Title: Add fingerprinting META Generator and HTTP headers for Drupal » poll is broken ( wasAdd fingerprinting META Generator and HTTP headers for Drupal)
Version: 6.x-dev » 7.x-dev
Category: feature » bug
Priority: Normal » Critical
Status: Patch (to be ported) » Active

Test fails without theme developer for me, as does looking at a poll with my own eyes the old fashioned way.

cburschka’s picture

Which tests fail for you? In my case, with theme developer enabled, only the 7 "Choice bar is themed" tests failed, and they passed when I disabled theme developer.

The poll bars don't look right, but that's a CSS problem and it is also caused by theme developer.

catch’s picture

Title: poll is broken ( wasAdd fingerprinting META Generator and HTTP headers for Drupal) » Add fingerprinting META Generator and HTTP headers for Drupal
Version: 7.x-dev » 6.x-dev
Category: bug » feature
Priority: Critical » Normal
Status: Active » Postponed

Whoops.

Run all tests - poll has 7 failures.
Run poll test by itself - all passes.

With or without this patch.

Of course I was running all tests on HEAD, and narrowed down to poll test when trying to find why it was breaking. Sorry.

lilou’s picture

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

Status: Postponed » Active
lilou’s picture

Version: 7.x-dev » 6.x-dev
Status: Active » Postponed

oups, back to previous status ...

catch’s picture

Status: Postponed » Patch (to be ported)
jsaints’s picture

I can confirm that this patch breaks the block module in the block_admin_display() function and any module that tries to change the theme using $custom_theme variable.

Bug background:
1) enable two themes in theme settings
2) go to admin/build/block
3) click the local menu task to change blocks for a theme which is not the default (active) theme. For example if foo_theme is your active theme click on /admin/build/block/list/bar_theme
4) the list of blocks enable displays for the default active foo_theme, instead of the bar_theme that the user selected.
5) saved changes affect only the default theme and not the selcted theme

The block module tries to change the theme to bar_theme, but cannot because the theme() calls in system_init have already initialized the theme (I found this using var_dump(debug_backtrace());
in init_theme()). The problem comes from calling theme() functions too early in the init process. After these lines in this patch:

// Emit the META tag in the HTML HEAD section
theme('meta_generator_html', $version);

// Emit the HTTP Header too
theme('meta_generator_header', $version)

No other module can change the theme by settings the $custom_theme variable. This bug is not present in D6 where these theme() lines are not present.

Please see the discussion on the dev mailing list called "$custom_theme when does it take effect... when does it not" at http://lists-new.drupal.org/pipermail/development/2008-August/030893.html

kbahey’s picture

Version: 6.x-dev » 7.x-dev
Status: Patch (to be ported) » Needs work

Setting this to CNW then.

We need to delay the call to theme() so it does not initialize the them that early.

catch’s picture

Priority: Normal » Critical

Marking as critical since blocks admin is properly broken.

kbahey’s picture

Status: Needs work » Needs review
StatusFileSize
new3.13 KB

Here is a patch to HEAD that removes calling theme() altogether, while still allowing the user to override this functionality using a variable.

Works for me, please test and review ...

chx’s picture

Title: Add fingerprinting META Generator and HTTP headers for Drupal » early theme breaks Drupal
Assigned: kbahey » chx
Category: feature » bug
Status: Needs review » Needs work
chx’s picture

Title: early theme breaks Drupal » META Generator and HTTP headers for Drupal breaks custom_theme
Component: base system » theme system
Status: Needs work » Needs review
StatusFileSize
new423 bytes

What I hoped can't be fixed. But this bug can...

Edit. testing instructions: enable Marvin and go to admin/build/block/list/marvin . Observe the Garland theme without patch and Marvin with the patch.

dries’s picture

On a related note, we need a test case to verify that the $custom_theme hack works, and continues to work. Would be great if that could be part of this patch. It is the perfect test case for it, it seems.

chx’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.94 KB

#14 needs a revert and when someone has the time to write a test for the modified version as outlined in #42 then we can commit this again. It does not seem to be an easy affair.

chx’s picture

StatusFileSize
new4.87 KB
chx’s picture

Of course committing the trivial fix in #42 and not demanding an almost impossible to write test is an option...

webchick’s picture

chx and I are discussing how a test for this might be written. I think we've come up with a solution: checking the HTML for a style.css to see if it reflects the new theme that was selected.

chx’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.87 KB

After some discussion with webchick the test is not that impossible after all.

webchick’s picture

Status: Needs review » Fixed

I tested chx's patch and it works, and test passes. I also tried backing out the fix, and the test correctly reports the failure of the code to work.

That makes this RTBC, so I went ahead and Ced it. Thanks!! :)

damien tournoud’s picture

Status: Fixed » Needs review
StatusFileSize
new805 bytes

Reopening... the HTML header is not printed, because template_preprocess_page is called *before* system_preprocess_page. That should do it, and pass the test.

webchick’s picture

Status: Needs review » Fixed

Awesome. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

chx’s picture

Title: META Generator and HTTP headers for Drupal breaks custom_theme » META Generator needlessly advertises "Drupal"
Status: Closed (fixed) » Active

I was concentrating too much on the breakage and not what was emitted here. WTF? We never, ever put anything on screen or in source that yells "Drupal" at you. Yes, fingerprinting is possible and easy but actually putting in Drupal in the source code? I dislike that, it does not mesh with us being a framework.

chx’s picture

Site information should contain the control for generator IMNSHO.

webchick’s picture

Title: META Generator needlessly advertises "Drupal" » Add fingerprinting META Generator and HTTP headers for Drupal
Status: Active » Closed (fixed)

Exposing a setting for this is completely overkill. Down with settings that only 0.000000001% of sites will ever use. Feel free to make Generator Alterator module in contrib that exposes one, however.

If you strongly dislike it, there is a theme function which can be overridden. Simply return ''; and voila. No meta generator tag.

I don't see the issue.

xmacinfo’s picture

I can confirm that this is easy to theme. :-)