question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Public API injects inline script into page.

See original GitHub issue

Issue Summary

When Public API is enabled in the Labs menu, Ghost injects an inline script tag into the page.

Steps to Reproduce

  1. Go to https://example.com/ghost/settings/labs/
  2. Enable the checkbox option for Public API
  3. Refresh your homepage an inline script tag will be injected

Technical details

Injecting an inline script into the page is problematic for sites that want to use Content Security Policy. One of the biggest security benefits of CSP is the ability to effectively neutralise XSS attacks. To do this, the execution of inline script is blocked. This leaves Ghost users the option of using the Public API and disabling this security feature or not using the Public API.

Is it possible the contents of the script tag can be externalised? Example script tag:

<script type="text/javascript">
    ghost.init({
        clientId: "ghost-frontend",
        clientSecret: "$value"
    });
</script>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
ErisDScommented, Aug 18, 2017

We’re aware that the way the Public API scripts are injected into the page are currently not ideal. We 100% intend to revisit this before removing the beta flag from this feature.

If anyone wants to raise PRs to improve the code, that would be great. Ideally these would use examples from other platforms and how they do this as reference material. cc @brettdewoody re #8918

0reactions
kevinansfieldcommented, Oct 15, 2018

We’re currently working on new API versions and an associated change in auth mechanism that will come with new SDKs that will not have any form of script injection.

Unfortunately we need to keep the injection around for backwards-compatibility until the next major version of Ghost. In the meantime we’ll be looking at ways to remove the render blocking behaviour.

Closing this issue because we’re unable to solve the CSP or script injection aspect at this time but it will eventually disappear as part of a future major release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to inject inline script when Content Security Policy is ...
I'm using Chrome Extension ReactJS which I'd like to insert this in popup.html : <script ...
Read more >
How to Inject JavaScript Code to Manipulate Websites ...
Open your Chrome developer tools by pressing F12, then identify the element with the pop-up. In this example, the iframe element with ID ......
Read more >
jantimon/html-webpack-plugin - Inline scripting support - GitHub
It's simple and good optimization to inline assets. Check Google Plus code, their first page has everything inlined for its view. Other not...
Read more >
Mitigate cross-site scripting (XSS) with a strict Content Security ...
A script injected by an attacker will be blocked by the browser as only the hashed inline script and any scripts dynamically added...
Read more >
Disable inline JavaScript for security - Gleb Bahmutov
The way to do this in the modern browsers is to set the 'Content-Security-Policy' (CSP) property, either via meta attribute or headers.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found