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

Added ZIM metadata to security dialogue box when opening ZIM for the first time #1250

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions i18n/en.jsonp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions i18n/es.jsonp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions i18n/fr.jsonp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions www/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ iframe._invert, iframe._mwInvert {
animation-duration: 0.1s;
}

#modal-archive-metadata-container {
border: solid 1px lightgrey;
padding: 10px;
margin-top: 1em;
margin-bottom: 1em;
}

.archive-metadata {
margin: 0;
padding: 0;
}

#modal-archive-metadata-warning {
font-style: italic;
font-weight: bold;
}

.container {
margin-bottom: 1.5em;
}
Expand Down
62 changes: 55 additions & 7 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,15 +640,63 @@ function focusPrefixOnHomeKey (event) {
}, 0);
}
}

/**
* Verifies the given archive and switches contentInjectionMode accourdingly
* @param {archive} the archive that needs verification
* @param {archive} archive the archive that needs verification
D3V-D marked this conversation as resolved.
Show resolved Hide resolved
* */
async function verifyLoadedArchive (archive) {
const response = await uiUtil.systemAlert(translateUI.t('dialog-sourceverification-alert') ||
'Is this ZIM archive from a trusted source?\n If not, you can still read the ZIM file in Safe Mode. Closing this window also opens the file in Safe Mode. This option can be disabled in Expert Settings',
translateUI.t('dialog-sourceverification-title') || 'Security alert!', true, translateUI.t('dialog-sourceverification-safe-mode-button') || 'Open in Safe Mode',
translateUI.t('dialog-sourceverification-trust-button') || 'Trust Source');
// We construct a HTML element to show the user in the alert with the metadata contained in it
D3V-D marked this conversation as resolved.
Show resolved Hide resolved
const metadataLabels = {
name: translateUI.t('dialog-metadata-name') || 'Name: ',
creator: translateUI.t('dialog-metadata-creator') || 'Creator: ',
publisher: translateUI.t('dialog-metadata-publisher') || 'Publisher: ',
scraper: translateUI.t('dialog-metadata-scraper') || 'Scraper: '
}

const verificationBody = document.createElement('div');

// text & metadata box
D3V-D marked this conversation as resolved.
Show resolved Hide resolved
const verificationText = translateUI.t('dialog-sourceverification-alert') || 'Is this ZIM archive from a trusted source?\n If not, you can still read the ZIM file in Safe Mode. Closing this window also opens the file in Safe Mode. This option can be disabled in Expert Settings';
D3V-D marked this conversation as resolved.
Show resolved Hide resolved

const metadataBox = document.createElement('div');
metadataBox.id = 'modal-archive-metadata-container';

const verifyName = document.createElement('p');
verifyName.id = 'confirm-archive-name';
verifyName.classList.add('archive-metadata');
verifyName.innerText = metadataLabels.name + (archive.name || '-');

const verifyCreator = document.createElement('p');
verifyCreator.id = 'confirm-archive-creator';
verifyCreator.classList.add('archive-metadata')
verifyCreator.innerText = metadataLabels.creator + (archive.creator || '-');

const verifyPublisher = document.createElement('p');
verifyPublisher.id = 'confirm-archive-publisher';
verifyPublisher.classList.add('archive-metadata');
verifyPublisher.innerText = metadataLabels.publisher + (archive.publisher || '-');

const verifyScraper = document.createElement('p');
verifyScraper.id = 'confirm-archive-scraper';
verifyScraper.classList.add('archive-metadata');
verifyScraper.innerText = metadataLabels.scraper + (archive.scraper || '-');

const verifyWarning = document.createElement('p');
verifyWarning.id = 'modal-archive-metadata-warning';
verifyWarning.innerText = translateUI.t('dialog-metadata-warning') || 'Warning: above data can be spoofed!';

metadataBox.append(verifyName, verifyCreator, verifyPublisher, verifyScraper);
verificationBody.append(verificationText, metadataBox, verifyWarning);
D3V-D marked this conversation as resolved.
Show resolved Hide resolved

const response = await uiUtil.systemAlert(
verificationBody.outerHTML,
translateUI.t('dialog-sourceverification-title') || 'Security alert!',
true,
translateUI.t('dialog-sourceverification-safe-mode-button') || 'Open in Safe Mode',
translateUI.t('dialog-sourceverification-trust-button') || 'Trust Source'
);

if (response) {
params.contentInjectionMode = 'serviceworker';
var trustedZimFiles = settingsStore.getItem('trustedZimFiles');
Expand Down Expand Up @@ -1630,7 +1678,7 @@ document.getElementById('archiveFilesLbl').addEventListener('keydown', function

/** Drag and Drop handling for ZIM files */

// Keep track of entrance event so we only fire the correct leave event
// Keep track of entrance event so we only fire the correct leave event
var enteredElement;

function handleGlobalDragenter (e) {
Expand Down Expand Up @@ -1682,7 +1730,7 @@ function hasInvalidType (typesList) {
for (var i = 0; i < typesList.length; i++) {
// Use indexOf() instead of startsWith() for IE11 support. Also, IE11 uses Text instead of text (and so does Opera).
// This is not comprehensive, but should cover most cases.
if (typesList[i].indexOf('image') === 0 || typesList[i].indexOf('text') === 0 || typesList[i].indexOf('Text') === 0|| typesList[i].indexOf('video') === 0) {
if (typesList[i].indexOf('image') === 0 || typesList[i].indexOf('text') === 0 || typesList[i].indexOf('Text') === 0 || typesList[i].indexOf('video') === 0) {
return true;
}
}
Expand Down
7 changes: 4 additions & 3 deletions www/js/lib/zimArchive.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,20 @@ function ZIMArchive (storage, path, callbackReady, callbackError) {
// Further metadata are added in the background below, and can be accessed later
return Promise.all([
that.addMetadataToZIMFile('Creator'),
that.addMetadataToZIMFile('Publisher'),
that.addMetadataToZIMFile('Scraper'),
that.addMetadataToZIMFile('Name'),
that.addMetadataToZIMFile('Language')
]).then(function () {
console.debug('ZIMArchive ready, metadata will be added in the background');
// Add non-time-critical metadata to archive in background so as not to delay opening of the archive
// DEV: Note that it does not make sense to extract illustration (icon) metadata here. Instead, if you implement use of the illustration
// metadata as icons for the loaded ZIM [kiwix-js #886], you should simply use the ZIMArdhive.getMetadata() function when needed
// metadata as icons for the loaded ZIM [kiwix-js #886], you should simply use the ZIMArchive.getMetadata() function when needed
D3V-D marked this conversation as resolved.
Show resolved Hide resolved
setTimeout(function () {
Promise.all([
that.addMetadataToZIMFile('Counter'),
that.addMetadataToZIMFile('Date'),
that.addMetadataToZIMFile('Description'),
that.addMetadataToZIMFile('Name'),
that.addMetadataToZIMFile('Publisher'),
that.addMetadataToZIMFile('Source'),
that.addMetadataToZIMFile('Title')
]).then(function () {
Expand Down
Loading