Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
// Use it explicitly
var messages = require("json!po!./locale/en_US/LC_MESSAGES/messages.po");
// Or add a loader into your webpack.config.js
loaders: [
{test: /\.po$/, loader: 'json!po'}
]
// And then require it like this
var messages = require("./locale/en_US/LC_MESSAGES/messages.po");
See po2json for a list of possible options. Use the format
option to change the output format, e.g. json!po?format=jed
or json!po?format=jed1.x
for the latest Jed format.
import Jed from 'jed'
// The Locale consists of a language and territory.
const language = langParts[0]
const territory = langParts[1].toUpperCase()
// Set complete
const locale = multipart ? language + '_' + territory : language
let i18n = null
export default {
async init() {
const langRaw = window.navigator.userLanguage || window.navigator.language
const langParts = langRaw.replace('-', '_').split('_')
const language = langParts[0]
const country = langParts.length > 1 ? '_' + langParts[1].toUpperCase() : ''
const locale = `${language}${country}`
let localeData
try {
localeData = await getLocaleData(locale)
} catch {
localeData = await getLocaleData(LOCALE_DEFAULT)
}
i18n = new Jed(localeData)
},
gettext(message) {
return i18n.gettext(message)
},
ngettext(msg1, msg2, n) {
return i18n.ngettext(msg1, msg2, n)
},
}
// A runtime exception will be throw every time that the requested locale file cannot be found.
// Webpack uses a regular expression to build all locales as separate bundles.
async function getLocaleData(locale) {
return import(`${LOCALE_ROOT}/${locale}/LC_MESSAGES/messages.po`)
}
Language fallback map stored at ${LOCALE_ROOT}/config
:
---
default: en_US
map:
en: en_US
ru: ru_RU
uk: ru_RU
de: de_DE
...
locale
module:
import Jed from 'jed'
let i18n
let localeConfig
export default {
async init() {
const localeConfig = await import(`${LOCALE_ROOT}/config`)
const localeDefault = localeConfig['default']
const map = localeConfig['map']
const langRaw = window.navigator.userLanguage || window.navigator.language
const langParts = langRaw.replace('-', '_').split('_')
const language = langParts[0]
const country = langParts.length > 1 ? '_' + langParts[1].toUpperCase() : ''
const locale = `${language}${country}`
let localeData
try {
localeData = await getLocaleData(locale)
} catch {
const localeNext = map.hasOwnProperty(language) ? map[language] : localeDefault
localeData = await getLocaleData(localeNext)
}
i18n = new Jed(localeData)
},
gettext(message) {
return i18n.gettext(message)
},
ngettext(msg1, msg2, n) {
return i18n.ngettext(msg1, msg2, n)
},
}
// A runtime exception will be throw every time that the requested locale file cannot be found.
// Webpack uses a regular expression to build all locales as separate bundles.
async function getLocaleData(locale) {
return import(`${LOCALE_ROOT}/${locale}/LC_MESSAGES/messages.po`)
}
Then in your common shared code:
const localePromise = locale.init()
const documentPromise = new Promise(function(resolve, reject) {
document.addEventListener('DOMContentLoaded', resolve, false)
})
init([localePromise, documentPromise])
Finally in your entry code:
import init from 'init'
init().then(function() {
console.log('The locale module is now ready.')
})
FAQs
PO loader module for webpack
The npm package po-loader receives a total of 13,422 weekly downloads. As such, po-loader popularity was classified as popular.
We found that po-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.