How To: Generate Random URL

ebrittwebb's picture

(Reposting...last post was deleted)

For certain content on a site, I want to implement "security by obscurity" by having the posts show up only in restricted views and by making the URLs for those posts a set of random, unguessable characters (like Microsoft does with GUID).

So, I need guidance in two parts:

  1. What module (presumably CCK-related) or trick will create a set of random, unguessable characters that I can then use as replacement token in pathauto?

  2. How do I disable the default node URLs (e.g., www.xxx.com/node/123) which still work even when their links have been replaced by pathauto?

Thanks,
Erik

Login to post comments

Random tokens

ethanw's picture
ethanw - Wed, 2009-09-02 14:49

Re: 1, I haven't tried this myself but did find this recent update to the Token module, http://drupal.org/node/194407, and taking a look at the patch it looks like Token should give you the [random-sha1] token which will give a pretty hefty random string. May be useful prepending this with the nid or date or such, in the one in X million chance you get identical sha hashes.

Re: 2, Global Redirect automatically redirects node/* URLs to their aliases, but my guess is that, for security's sake, that won't due for you. All I can think of in that case is .htaccess. Can you forbid access to all node/* paths?


I would stick this at the top of page.tpl.php

peter panes's picture
peter panes - Wed, 2009-09-02 15:11

<?php
//// Show nothing if URL contains /node/ and node is not being edited or tracked or cloned /////
if (arg(2) != "edit" && arg(2) != "clone" && arg(2) != "track" && substr_count(drupal_get_path_alias(request_uri()),"/node/") == 1) {
print
"stop trying to hack my site!!!!";
return;
}
?>


tokenSTARTERKIT.module

greggles's picture
greggles - Wed, 2009-09-02 15:41

The starterkit contains random tokens. See the README.txt with recent token module releases for examples.

As others have pointed out, you'll want to block access via the node/NID to make this more secure.

--
http://growingventuresolutions.com | http://drupaldashboard.com | http://drupal.org/books


CCK Computed Field

jeromebaum - Wed, 2009-09-02 16:57

You can use a computed field that generates a UID for each node and stores it in the database (so it remains constant). Then use that field in the token module.

To prevent access via /node/* URLs others above have posted valid solutions. You'll also want to make sure that nodes aren't accessible in other places, including the /node and /search displays.

If you need help with the snippet for the computed field, feel free to email me at jerome@jeromebaum.com.


Helpful PHP Functions

tylerwalts's picture
tylerwalts - Wed, 2009-09-02 21:03

If you end up writing & calling your own hooks to generate your 'GUID's, here's a link with 4 function examples:

http://phpgoogle.blogspot.com/2007/08/four-ways-to-generate-unique-id-by...

Cheers,

  • Tyler