Problem/Motivation

Nodes become inaccessible (403 HTTP code) when using a token which will generate a pattern starting with a dot.

Steps to reproduce

  1. Create an alias pattern with the title of the node as token for all content types
  2. Make sure that the "strings to remove" setting at /admin/config/search/path/settings has at least "a" in it to be removed
  3. Create a node with the title "A.Foo"
  4. The alias will be ".foo"
  5. In many well configured webservers this will result in a 403 HTTP code as the webserver prevents loading hidden files (which start with a dot)

Proposed resolution

Check that an alias can't start with a dot.

I'm not sure if this should be a setting or not. I can't find any reason (yet) why you really want to have an alias starting with a dot but if someone got a case, it should become a setting to disable removing a starting dot.

CommentFileSizeAuthor
#3 pathauto_test.png72.89 KBsijumpk
#2 remove-starting-dots.patch494 bytesrik wijnen

Issue fork pathauto-3398583

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Rik Wijnen created an issue. See original summary.

rik wijnen’s picture

StatusFileSize
new494 bytes

Patch added which could fix this.

sijumpk’s picture

StatusFileSize
new72.89 KB

Tried creating a node (without applying patch) with title "A.Foo" and the resulted url is /afoo, as expected. "a" is there in the "strings to remove" list while doing this. It seems like all dots are getting replaced irrespective of its position. Its done inside AliasCleaner::cleanString method. Is it just me who cannot reproduce this problem?

meeni_dhobale’s picture

I also tried to reproduce this issue without applying the patch with title "A.Foo" and my URL is "/afoo". I didn't see any kind of 403 HTTP code. I am also not able to reproduce this issue.

rik wijnen’s picture

I'm sorry, I realize that I was forgotten one setting;
In step 2, you have to select "no action (do not replace)" for "period (.)" in the "punctuation" section of /admin/config/search/path/settings too to make it break.

If you make sure "a" is in the list AND dots must not be replaced, a node with title "A.Foo" will result in url ".foo".

And yes, I'm telling the system to not replace dots but this is a special case because this one will break your site with widely used server configurations. Maybe it should be a setting in the module to prevent urls being starting with a dot, so it can be enabled if your webserver does not allow files and directories to begin with a dot.

mably’s picture

Status: Active » Needs work

Could we have an MR please?

mably’s picture

Status: Needs work » Needs review

Leading dot removal in path aliases

Problem

When the period punctuation setting is set to "Do nothing", path aliases could start with a dot (e.g. .hidden-page). Leading dots in URL paths create hidden paths that may be blocked by web servers (Apache/Nginx) or cause unexpected behavior.

Changes

  • AliasCleaner.php: Added ltrim($output, '.') to strip leading dots from cleaned strings, after all other processing (transliteration, punctuation handling,
    lowercasing) is complete.
  • PathautoKernelTest.php: Added kernel test covering leading dot removal with period punctuation set to "do nothing", verifying:
    • Single leading dot is stripped (.hiddenhidden)
    • Multiple leading dots are stripped (..hiddenhidden)
    • Inner dots are preserved (.hidden.filehidden.file)
    • Strings without leading dots are unaffected (normal.filenormal.file)

Design decision

No configuration setting was added. This is an unconditional sanitization step, consistent with other non-configurable cleanups (whitespace replacement, duplicate separator trimming, length truncation).

mably’s picture

Assigned: Unassigned » berdir
mably’s picture

Category: Task » Bug report

anybody made their first commit to this issue’s fork.

anybody’s picture

Version: 8.x-1.11 » 8.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

Nice fix, totally makes sense to me in addition to #2728725: Special characters like tab or spaces in pattern can break alias generation.

Still all green after rebase and code LGTM! RTBC