OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

htaccess secret.json file access from a given javascript (service worker) file [duplicate]

  • Thread starter Thread starter Jani88
  • Start date Start date
J

Jani88

Guest
How do I check in the htaccess file that only the service worker.js can access the secret.json file?

The Host or IP address filtering is not good.

I'm looking for a Vanilla JS solution that only allows the service worker to read the file.

.htaccess file

Code:
Options All -Indexes
ServerSignature Off

SetEnvIf Referer ".example\.com" localreferer

<FilesMatch "\.json$">
    Require all denied
    Require env localreferer
</FilesMatch>

SetEnvIf Referer "serviceworker.js" swjsreferer?????? :S

secret.json

Code:
{
'name': 'test'
}

service worker.js

Code:
        await fetch('https://example.com/secret.json', {
          }).then(response => {
            return response.json();
          })
          .then(data => {
            console.log(data);
          })
          .catch(error => {
            console.log(error);
          });
<p>How do I check in the htaccess file that only the service worker.js can access the secret.json file?</p>
<p>The Host or IP address filtering is not good.</p>
<p>I'm looking for a Vanilla JS solution that only allows the service worker to read the file.</p>
<p>.htaccess file</p>
<pre><code>Options All -Indexes
ServerSignature Off

SetEnvIf Referer ".example\.com" localreferer

<FilesMatch "\.json$">
Require all denied
Require env localreferer
</FilesMatch>
</code></pre>
<p>SetEnvIf Referer "serviceworker.js" swjsreferer?????? :S</p>
<p>secret.json</p>
<pre><code>{
'name': 'test'
}
</code></pre>
<p>service worker.js</p>
<pre><code> await fetch('https://example.com/secret.json', {
}).then(response => {
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.log(error);
});
</code></pre>
Continue reading...
 
Top