Page MenuHomePhabricator

Aprhont - Adding cookie-prefix, as config option, and into cookie methods
ClosedPublic

Authored by aarwine on Jan 16 2014, 12:13 AM.
Tags
None
Referenced Files
F14036545: D7979.diff
Sun, Nov 10, 10:43 AM
F14018718: D7979.diff
Tue, Nov 5, 6:48 PM
F14012776: D7979.id18075.diff
Fri, Nov 1, 6:19 PM
F14012166: D7979.id18058.diff
Fri, Nov 1, 7:38 AM
F14011003: D7979.id18069.diff
Thu, Oct 31, 3:17 PM
F14011002: D7979.id18071.diff
Thu, Oct 31, 3:17 PM
F14011001: D7979.id18058.diff
Thu, Oct 31, 3:17 PM
F14011000: D7979.id.diff
Thu, Oct 31, 3:17 PM

Details

Summary

Cookie-prefix should fix phabricator instances where x.com and x.y.com have conflicting cookie names

Test Plan

Pushed branch to dev.phab.example.com, logged into phab.example.com and into dev.phab.example.com.

Diff Detail

Branch
cookieprefix
Lint
Lint Passed
Unit
Tests Passed

Event Timeline

Biggest concerns:
After I diff'ed this I realized there's probably tests somewhere that I need to add

Wasn't sure how to properly minimize the number of getEnvConfigs; originally was hoping to not have to edit getCookie / clearCookie but that didn't work out as nicely as I hoped.

Lastly, wondering if null is a solid default config. It seems to best fit a least amount of changes paradigm, but it might be better off using a random string? Or base-uri? This would prevent cookie naming collisions on phab.example.com / dev.phab.example.com, and in the case of load balanced instances where multiple nodes are hosting phab.example.com local config (normally) would be shared, and so would db. Thus would still not require config of this option.

Minor things:

  • If the prefix has strlen(), let's add a separator character (like _) so that it's not possible for cookie bc from namespace a to collide with cookie abc from no namespace..
  • By convention, prefer $a.$b over $a . $b (no space around . operator). I thought we had lint for this already, but maybe not.
  • It would be slightly cleaner to add a setCookiePrefix() method and call it from AphrontDefaultApplicationConfiguration->buildRequest().
  • I don't think you really need to add tests for this as long as you tested locally.
  • We should not namespace by default. If nothing else, this will break every session on every install everywhere, and doesn't seem like it provides much benefit. I think this use case is just barely reasonable as-is, and putting a multitude of installs behind some weird LB thing should definitely be done in a more thoughtful manner (we have substantial planning around our own intents to do this).
src/applications/config/option/PhabricatorCoreConfigOptions.php
81–82

For consistency, add a period to make this a full sentence.

aarwine updated this revision to Unknown Object (????).Jan 16 2014, 7:15 PM
  • Style changes regarding concatenation, typos
  • Added helper methods in hopes of being a bit cleaner
aarwine updated this revision to Unknown Object (????).Jan 17 2014, 1:32 AM

Refactored to properly use property on the object

A couple more inlines, this is 90% of the way there. D7988 should fix the lint issue, which was a bug in arc.

src/aphront/AphrontRequest.php
282

Implement this as:

if (strlen($this->cookiePrefix)) {
  return $this->cookiePrefix.'_'.$name;
} else {
  return $name;
}

This method should also be private.

285–287

With the above implementation, this can then be simplified to:

$name = $this->getPrefixedCookieName($name);

If there's no prefix, it will just return $name unmodified. If there is a prefix, it will apply the prefix correctly.

293–295

As above.

361–363

As above.

src/aphront/configuration/AphrontDefaultApplicationConfiguration.php
110 ↗(On Diff #18069)

This is the syntax error: missing semicolon at the end of this line.

src/applications/config/option/PhabricatorCoreConfigOptions.php
82

For consistency, add a period at the end of the sentence:

...cookie names.
               ^

Other summary text uses this style.

aarwine updated this revision to Unknown Object (????).Jan 17 2014, 4:38 AM

Moved strlen logic into getPrefixedCookieName(). This simplifies the strlen logic.

Closed by commit rPe6a6c265b04c (authored by @aarwine, committed by @epriestley).