Skip to content

Add strict option for http url in asset #22510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

Add strict option for http url in asset #22510

wants to merge 6 commits into from

Conversation

RedBoool
Copy link

@RedBoool RedBoool commented Apr 24, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #21249
License MIT
Doc PR symfony/symfony-docs#7848 / In progress

*
* @return array
*/
protected function splitBaseUrl(array $urls, $isStrictHttp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be private.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if ($sslUrls && $baseUrls !== $sslUrls) {
$this->sslPackage = new self($sslUrls, $versionStrategy);
$urlList = $this->splitBaseUrl($this->baseUrls, $isStrictHttp);
if (!empty($urlList['httpsUrl']) && $this->getContext()->isSecure()) {
Copy link
Member

@GromNaN GromNaN Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context is stateful, you must check isSecure in getBaseUrl, not in the constructor.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

array(false, array('http://example.com', 'http://example.net', 'https://example.com', 'https://example.net'), '', 'fooa', 'http://example.net/fooa?v1'),

array(true, array('http://example.com', 'http://example.net', 'https://example.com', 'https://example.net'), '', 'foo', 'https://example.com/foo?v1'),
array(true, array('http://example.com', 'http://example.net', 'https://example.com', 'https://example.net'), '', 'fooa', 'https://example.net/fooa?v1'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a test case with a protocol-relative URL.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*/
private function splitBaseUrl(array $urls, $isStrictHttp)
{
$urlList = array('httpUrl' => array(), 'httpsUrl' => array(), 'fullUrl' => array());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this array of arrays, having 2 private properties baseSecureUrls and baseUnsecureUrls.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Apr 25, 2017
@RedBoool RedBoool changed the title [WIP] Add strict option for http url in asset Add strict option for http url in asset May 9, 2017
@nicolas-grekas nicolas-grekas changed the base branch from master to 3.4 May 23, 2017 17:05
@javiereguiluz
Copy link
Member

@RedBoool thanks for contributing this feature!

I'd like to ask you a question:

Is really a technical issue to use HTTPS on HTTP pages? Will browsers display any warning message or will it affect your application or your end users in any other way? I know it's an issue the other way (using HTTP on HTTPS pages).

  • If it's not a problem, I'd say let's not add this config option and keep the existing behavior.
  • If it's a problem, I'd recommend to not add this config option, but change the existing behavior as if we were setting $isStrictProtocol to true.

What do others think?

@RedBoool
Copy link
Author

RedBoool commented Aug 7, 2017

This is not a technical issue, it's a financial issue.
Some CDN charge you more for https than for http.

The aim of this PR is to help us pay the right price, no more, no less

@nicolas-grekas
Copy link
Member

not add this config option, but change the existing behavior as if we were setting $isStrictProtocol to true

@RedBoool would that fit your request? ping @symfony/deciders would that be OK to you?

@RedBoool
Copy link
Author

That perfectly match my needs.
My first thought was to do it this way, but didn't want to introduce a breaking change.

@weaverryan
Copy link
Member

not add this config option, but change the existing behavior as if we were setting $isStrictProtocol to true
RedBoool would that fit your request? ping symfony/deciders would that be OK to you?

It makes me a bit nervous... if your protocol is http, and you have a mixture of http and https base URLs... right now, they will "round robin". After this PR, it will only round robin in the http base URLs. That doesn't seem horrible, but it will be really hard to notice.

@nicolas-grekas
Copy link
Member

Moving to 4.1 as it looks like the discussion is not over.

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Oct 8, 2017
@nicolas-grekas nicolas-grekas modified the milestones: 4.1, next Apr 20, 2018
@javiereguiluz
Copy link
Member

Maybe it's time to rethink this feature proposal. HTTPS is no longer optional for the web. Google and others are pushing hard to make it mandatory. According to Google's data (https://transparencyreport.google.com/https/overview) more than 70% of web traffic is now encrypted. So I guess CDNs charging more for HTTPS traffic will be soon out of the market.

@dunglas
Copy link
Member

dunglas commented Jul 4, 2018

👎 on my side. Mixed content should be avoided, and using HTTPS everywhere is a best practice we must encourage.

@RedBoool RedBoool closed this Jul 4, 2018
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.2 Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants