laravel-datatables icon indicating copy to clipboard operation
laravel-datatables copied to clipboard

toJson causes encoding of utf-8 characters

Open avatarofhope2 opened this issue 1 year ago • 4 comments

Summary of problem or feature request

When selecting data with valid utf-8 characters, the JsonResponse html encodes the data. I can disable this by using the rawColumns method, but I do want it to escape html specific things, just not normal characters that would not have an impact on xss. I think that maybe characters like ' (' or U+0027) should maybe be unmangled by default. My apologies if I've overlooked something or this has been addresses since version 8. I searched around in the issues, and while I did find some issues related to this, I didn't spot anything specific to this issue.

Code snippet of problem

return DataTables::eloquent(MyModel::select())->toJson();

data that shows the issue: "COEUR-D'ALENE" is returned as "COEUR-D'ALENE-ID"

System details

  • Centos 7
  • PHP 7.2
  • 5.6
  • 8

avatarofhope2 avatar Feb 15 '24 20:02 avatarofhope2

I think you need to use rawColumns?

yajra avatar Mar 18 '24 10:03 yajra

I am using rawColumns, but it could be a security issue, if the column data could contain html/javascript, right? I'm trying to establish a difference between utf-8 and html when it comes to encoding data from the database.

avatarofhope2 avatar Apr 02 '24 23:04 avatarofhope2

Yes, rawColumns will also allow the js script. Maybe try using the column.render api.

yajra avatar May 03 '24 01:05 yajra

I appreciate the thought, but I tend to re-use these APIs for more than just datatables front-ends, so I'd prefer to get just the exact utf-8 data as-is, except if there is html/js which could pose a security risk.

avatarofhope2 avatar May 03 '24 02:05 avatarofhope2

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jun 03 '24 00:06 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Jun 10 '24 00:06 github-actions[bot]