Skip to content
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

CSP violation in Stimulus implementation #8433

Closed
Mat-Sedkowski opened this issue Jun 18, 2024 · 4 comments · Fixed by #8565
Closed

CSP violation in Stimulus implementation #8433

Mat-Sedkowski opened this issue Jun 18, 2024 · 4 comments · Fixed by #8565
Assignees
Labels
Milestone

Comments

@Mat-Sedkowski
Copy link

Are you requesting a feature, reporting a bug or asking a question?

Reporting a bug / Asking a question

What is the current behavior?

I have an issue with your library after we turned on CSP. Current implementation in rails app via Stimulus controller is prone to CSP violation both in inline styles and script.

What is the expected behavior?

Implementation where I don't need to apply inline code/styles or a method to fetch nonce from page meta

How would you reproduce the current behavior (if this is a bug)?

  1. Add survey-jquery in package json
  2. Import it into your stimulus controller
  3. Use in app

Provide the test code and the tested page URL (if applicable)

Test code

// Stimulus controller 
import { Controller } from '@hotwired/stimulus';
import { Helpers } from '../../utils/helpers';
import * as Survey from 'survey-jquery';

export class SurveyjsQuestionnaireFormControllerShared extends Controller {

connect() {
    Survey.FunctionFactory.Instance.register('age', this.age);
    Survey.FunctionFactory.Instance.register('ageByMonth', this.ageByMonth);
    Survey.FunctionFactory.Instance.register('ageByDays', this.ageByDays);
    // Survey.StylesManager.Enabled = false; <- Tried this doesn't work 
    // Problematic line 1 - inline styles issue
    Survey.StylesManager.applyTheme('bootstrap');

    this.survey = this.buildSurvey();
}

buildSurvey = () => {
    const requiresQuestionnaire = this.data.get('requires-questionnaire') == 'true';
    // Problematic line 2 - inline script issue
    const survey = new Survey.Model(this.data.get('configuration'));

    survey.ignoreValidation = !requiresQuestionnaire;
    survey.checkErrorsMode = 'onValueChanged';

    return survey;
  };
}

Specify your

  • browser: chrome
  • browser version: 125.0.6422.60
  • surveyjs platform (angular or react or jquery or knockout or vue): jquery
  • surveyjs version: 1.11.2
@andrewtelnov
Copy link
Member

andrewtelnov commented Jun 18, 2024

@Mat-Sedkowski We are currently using knockoutJS in survey-jquery. You can use survey-jquery-ui with survey-core that we have just released. It uses pReact version of our library.
knockoutJS is an old library and it uses eval inside the library. There is nothing wrong with it since it uses eval for their templates.

Thank you,
Andrew

@Mat-Sedkowski
Copy link
Author

Thank you, CSP issue solved.

@marat-y
Copy link

marat-y commented Jul 8, 2024

I've switched to survey-jquery-ui and our survey.render(container) seems to stopped working.

I've compared render method definitions between libraries and here's what I've found:

survey-jquery:

function(element) {
                      if (element === void 0) {
                        element = null;
                      }
                      this.implementor.render(element);
                    }

survey-jquery-ui:

function(element) {
                      if (element === void 0) {
                        element = null;
                      }
                      if (this.renderCallback) {
                        this.renderCallback();
                      }
                    }

Any ideas on what I'm missing to make survey-jquery-ui render surveys properly? Currently nothing's rendered and I don't see any JS console errors.

    "survey-core": "^1.11.5",
    "survey-jquery-ui": "^1.11.5",

@tsv2013
Copy link
Member

tsv2013 commented Jul 10, 2024

@marat-y Thank you for pointing this out. We'll fix it. Meanwhile we decided to deprecate the survey-jquery-ui package: actually it is the survey-react-ui package with the preact engine embedded. It uses jQuery to add three rendering functions to it. We decided to replase this package with the survey-ui one that will not reference jQuery and can be uased as a blackbox in vanilla JS projects.

@tsv2013 tsv2013 self-assigned this Jul 10, 2024
tsv2013 pushed a commit that referenced this issue Jul 15, 2024
@tsv2013 tsv2013 linked a pull request Jul 15, 2024 that will close this issue
@OlgaLarina OlgaLarina added this to the v1.11.7 milestone Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants