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

JSINFO moved to <meta> #4242

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions inc/template.php
Expand Up @@ -373,13 +373,8 @@ function tpl_metaheaders($alt = true)
'href' => DOKU_BASE . 'lib/exe/css.php?t=' . rawurlencode($conf['template']) . '&tseed=' . $tseed
];

$script = "var NS='" . (isset($INFO) ? $INFO['namespace'] : '') . "';";
if ($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
$script .= "var SIG=" . toolbar_signature() . ";";
}
jsinfo();
$script .= 'var JSINFO = ' . json_encode($JSINFO, JSON_THROW_ON_ERROR) . ';';
$head['script'][] = ['_data' => $script];
$head['meta'][] = ['itemprop' => 'JSINFO', 'content' => base64_encode(json_encode($JSINFO, JSON_THROW_ON_ERROR))];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the base64 encoding?

Copy link
Author

@fjf2002 fjf2002 Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this PR was just thought as a quick proof-of-concept. I used base64 as kind-of quick means to safely escape the string properly for use in the HTML meta attribute. htmlspecialchars does not escape double quotes, so that would fail when constructing the meta tag using double quotes.

Feel free to suggest anything different.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this PR was just thought as a quick proof-of-concept.

Not to rain on your parade, I appreciate your desire to help, but I can do a quick proof of concept myself - no problem. The bigger task is to bring it to a state where it works well enough to be merged with confidence and for that a quick proof of concept PR is not really helping much.


// load jquery
$jquery = getCdnUrls();
Expand Down
7 changes: 7 additions & 0 deletions lib/exe/js.php
Expand Up @@ -99,6 +99,13 @@ function js_out()
ob_start();

// add some global variables
echo "const JSINFO = JSON.parse(atob(document.head.querySelector('meta[itemprop=JSINFO]').content));";
// TODO Is this neccessary?
echo "const NS = JSINFO.namespace;";
// TODO From template.php. Is this neccessary?
if ($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
echo "var SIG=" . toolbar_signature() . ";";
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JS dispatcher runs without a session and the results are meant to be cacheable. So no user dependent information (like the signature) can be set here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add SIG into JSINFO? See the updated PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to admit I adapted the function toolbar_signature(). At least the test case will have to be adapted, too.

echo "var DOKU_BASE = '" . DOKU_BASE . "';";
echo "var DOKU_TPL = '" . tpl_basedir($tpl) . "';";
echo "var DOKU_COOKIE_PARAM = " . json_encode([
Expand Down