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

Scrub body_data / data params too (e.g. POSTed JSON) #3

Merged
merged 8 commits into from
Sep 18, 2023

Commits on Sep 18, 2023

  1. Scrub body_data params too (e.g. POSTed JSON)

    If we have `$c->req->body_data` - for e.g. the request was a POST with
    a JSON body which Catalyst has decoded into `$c->req->body_data` - then
    scrub HTML in there too (but applying the same `ignore_params` checks so
    that you can exempt certain JSON body params from scrubbing).
    
    Also moved the ignore_params tests into t/03_params.t, and added the
    tests for this new feature there too - don't need so many individual
    test apps, when most features can be tested with a single test app.
    bigpresh committed Sep 18, 2023
    Configuration menu
    Copy the full SHA
    cffe04c View commit details
    Browse the repository at this point in the history
  2. Compare request statuses more usefully

    Use `is()` not `ok()` so that, if the request status is *not* what we
    expect, we get to see what it actually was.
    bigpresh committed Sep 18, 2023
    Configuration menu
    Copy the full SHA
    00393c8 View commit details
    Browse the repository at this point in the history
  3. Support scrubbing $c->req->data from C::Action::REST

    If Catalyst::Action::REST / Catalyst::Controller::REST is in use, the
    request object will have a `data()` method for deserialised data as added by
    the Catalyst::TraitFor::Request::REST role which ought to be scrubbed too.
    
    To support this,
    
    (a) the scrubbing needs to happen later in the request flow - now
        `hooking dispatch()` instead of `prepare_parameters()`
    (b) to avoid the data not being read if the request body had already
        been read by `$c->req->body_data`, the fix in this PR is needed:
        perl-catalyst/catalyst-runtime/pull/186
        Until such time, dirtily monkey-patch the `seek()` in.
    bigpresh committed Sep 18, 2023
    Configuration menu
    Copy the full SHA
    2b6ea03 View commit details
    Browse the repository at this point in the history
  4. Trigger on execute() instead.

    This seems to be the right time to go scrubbing, without the scrubbed
    data getting accidentally clobbered, and/or happening too late.
    bigpresh committed Sep 18, 2023
    Configuration menu
    Copy the full SHA
    222e5d5 View commit details
    Browse the repository at this point in the history
  5. Catalyst needs to be loaded for us to load.

    Our monkey-patch pokes at Catalyst, so Catalyst needs to be loaded
    first.
    
    In the usual way of loading the plugin, e.g. listing the plugins you
    want on the `use Catalyst` line, that's fine, but here we're testing
    just that the plugin compiles, so we will need to load Catalyst first.
    bigpresh committed Sep 18, 2023
    Configuration menu
    Copy the full SHA
    c464756 View commit details
    Browse the repository at this point in the history
  6. Avoid sub redefined warnings.

    Yes, we're redefining a sub, intentionally, to monkey-patch, so silence
    that warning.
    bigpresh committed Sep 18, 2023
    Configuration menu
    Copy the full SHA
    5bd94a6 View commit details
    Browse the repository at this point in the history
  7. Remove extra debuggery.

    bigpresh committed Sep 18, 2023
    Configuration menu
    Copy the full SHA
    d008d5e View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    4330290 View commit details
    Browse the repository at this point in the history