PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 3, 2022

[FIXED] Chrome Extension sends POST request to local HTTPS address instead of HTTP

 February 03, 2022     ajax, cakephp, google-chrome-extension, https, jquery     No comments   

Issue

I'm building a Chrome Extension and it's supposed to send a POST request to my local site (Apache Server HTTP site), but I get an error when trying to do that. It send data to https:// even though I specified it to be send to http://

On a button click I call the test2 function. It tells AJAX that data needs to be send to a specific URL. When I click that button I get this error SSL_ERROR

This is my popup.js piece of code:

function test2(z,y) {
//makes sure that both parameters are present
if(z)
  console.log(z );
if(y)
  console.log(y );

//save data from POST in ff variable
ff = $("#frm");

//display all the information gathered from the extension popup, it works fine
console.log(ff);
console.log(ff.attr('id'));
console.log(ff.serialize());

//JQuery Ajax piece of code
$.ajax({
  type: 'POST',
  dataType:"json",
  crossDomain: true,
  //this is my local CakePHP website where I want to send data to
  url: 'http://land.register/register',
  data: ff.serialize(),
  method:'post' 
}).done(function( data ) {
    if ( console && console.log ) {
      console.log( "Sample of data:", data );
    }
  });}

My land.register\webroot\ .httaccess file looks like this (I didn't enable HTTPS or provide certificates for my local website)

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^ index.php [L]
</IfModule>

My manifest.json looks like this:

{

"name": "KW Automatische",
"version": "0.1",
"manifest_version": 2,
"description": "Automatyzacja przeszukiwania KW",
"incognito": "spanning",
"content_security_policy": "script-src 'self' 'unsafe-inline' https://ajax.googleapis.com; object-src 'self'",

"browser_action": {
  "default_icon": "icon-40@2x.png",
  "default_popup": "popup.html",
"default_title": "Click here!"
},
"content_scripts": [
  {
    "matches": ["http://*/*"],
    "js": ["contentScript.js","jquery.js"]
  }
],
"background": {
  "scripts": ["background.js"]
},
"icons": {
  "16": "/images/book.png",
  "32": "/images/book.png",
  "48": "/images/book.png",
  "128": "/images/book.png"
},
"permissions": [
  "activeTab",
  "http://*/*","*://*/*",
  "notifications",
  "storage"
]}

Solution

Got it resolved, I needed to remove <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> from popup.html file.



Answered By - pzmarlak
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing