Commit Graph

5108 Commits

Author SHA1 Message Date
Brian Gianforcaro
df04283d61 LibCore: Make Account::authenticate take a SecretString
To encourage users to use the SecretString API, change the API so that
Account::authenticate only accepts a SecretString.
2021-09-12 16:36:52 +02:00
Brian Gianforcaro
9e667453c7 LibCore: Make get_password return SecretString instead of String
We shouldn't let secrets sit around in memory, as they could potentially
be retrieved by an attacker, or left in memory during a core dump.
2021-09-12 16:36:52 +02:00
Brian Gianforcaro
3bf6902790 LibCore: Add SecretString, a buffer that is zero'd on destruction
We have a few places where we read secrets into memory, and then
do some computation on them. In these cases we should always make
sure we zero the allocations before they are free'd.

The SecureString wrapper provides this abstraction by wrapping a
ByteBuffer and calling explicit_bzero on destruction of the object.
2021-09-12 16:36:52 +02:00
Brian Gianforcaro
27a124f7d8 LibCrypto: Use explicit_bzero instead of memset to zero 'secure data'
PVS-Studio flagged this, as memset can be optimized away by the compiler
in some cases. We obviously don't want that to ever happen so make sure
to always use `explicit_bzero(..)` which can't be optimized away.
2021-09-12 16:36:52 +02:00
Andreas Kling
7691c7abcb LibWeb: Explicitly zero-initialize WindowObject::m_location_object 2021-09-12 16:32:12 +02:00
Sam Atkins
c66689ea76 LibWeb: Remove unused PropertyID parameter to StyleValue parsing methods
It's no longer used, and awkward to pass around.
2021-09-12 16:30:38 +02:00
Sam Atkins
8e4a4fd4db LibWeb: Remove "takes integer value" concept from parse_css_value()
This was only needed when numeric values had to be wrapped as Lengths,
and now serves no purpose.
2021-09-12 16:30:38 +02:00
Sam Atkins
2a141600a3 LibWeb: Correctly parse numeric and 'auto' z-index values
As with `opacity`, this code expected a Length value, when it is specced
to take a Number or `auto`. Now it's correct. :^)
2021-09-12 16:30:38 +02:00
Sam Atkins
b8c4320ffa LibWeb: Fix CSS opacity parsing
The StyleProperties code for opacity existed before NumericStyleValue
was a thing, and was affected by over-enthusiastic unitless-length
parsing, so it assumed everything was a length. Now it matches the
Color4 spec instead, accepting either a number, or a percentage.

We also get to remove the hack! :^)
2021-09-12 16:30:38 +02:00
Sam Atkins
8dc4f3763d LibWeb: Only apply the unitless-length quirk to needed properties
Previously, we applied the unitless length quirk to all numbers in
quirks mode. Now, we correctly only do so for the set of properties
listed in the quirks-mode spec:
https://quirks.spec.whatwg.org/#quirky-length-value

However, we do not yet prevent this quirk inside CSS expressions (like
`calc()`) as the spec directs.
2021-09-12 16:30:38 +02:00
Sam Atkins
3fa4f55f86 LibWeb: Add current_property_id to CSS ParsingContext
After `parse_css_value(PropertyID, TokenStream)`, we only need to know
the current PropertyID when checking for property-specific quirks, which
will take place in only 2 places, which happen deep down. Making the
current PropertyID part of the context means that those places can check
it easily, without us having to pass it to every one of the parsing
functions, which otherwise do not care.
2021-09-12 16:30:38 +02:00
Sam Atkins
9c873fc4dc LibWeb: Add CSS quirks information to Properties.json
Two CSS quirks are specced to only apply to specific properties:

- The hashless hex color quirk
  https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk
- The unitless length quirk
  https://quirks.spec.whatwg.org/#the-unitless-length-quirk

These are now represented in `Properties.json` like so:
```json
"property-name-here": {
    "quirks": [
        "hashless-hex-color",
        "unitless-length"
    ]
}
```

Every property that either of those two quirks applies to is included in
`Properties.json` and now has their quirks listed. :^)
2021-09-12 16:30:38 +02:00
Sam Atkins
8ddce2faaf LibWeb: Don't assert if reconsuming on an empty TokenStream
This fixes #9978.

When a TokenStream is empty, reading its `current_token()` still returns
a token (for EOF) so it makes sense to allow users to
`reconsume_current_input_token()` that token, so they do not have to
handle that themselves. Instead of VERIFY()ing, we can just no-op when
reconsuming token 0.
2021-09-12 16:11:48 +02:00
Andreas Kling
f58f58fb77 LibWeb: Fix out-of-order DOM tree dumps
There were a few calls to the standalone version of dump_tree() inside
the recursive version of dump_tree(), which led to the output getting
jumbled out of order.
2021-09-12 16:07:35 +02:00
Luke Wilde
678dd2d180 LibWeb: Expose the location object via Document.location
Both Window.location and Document.location use the same instance of the
Location object. Some sites use it via Window, some via Document.
2021-09-12 16:07:24 +02:00
Luke Wilde
ee5bac0891 LibWeb: Implement some custom JS internal overrides for Location
As required by the spec. Note that this isn't the full suite of
overrides.
2021-09-12 16:07:24 +02:00
Linus Groh
7991077284 LibWeb: Implement window.event as a [Replaceable] property
This is the result of debugging React DOM, which would throw a TypeError
when assigning to window.event in strict mode and then not complete
rendering - here:
https://github.com/facebook/react/blob/cae6350/packages/shared/invokeGuardedCallbackImpl.js#L134

With this change, the following minimal React example now works!

    <div id="app"></div>
    <script src="react.development.js"></script>
    <script src="react-dom.development.js"></script>
    <script>
        ReactDOM.render(
            React.createElement("h1", null, "Hello World"),
            document.getElementById("app")
        );
    </script>
2021-09-12 15:53:48 +02:00
Linus Groh
a05c998e69 LibWeb: Add A JS setter macro for [Replaceable] IDL properties
The [Replaceable] attribute "indicates that setting the corresponding
property on the platform object will result in an own property with the
same name being created on the object which has the value being
assigned. This property will shadow the accessor property corresponding
to the attribute, which exists on the interface prototype object."
(https://heycam.github.io/webidl/#Replaceable)

The spec doesn't tell how exactly this is supposed to be done, but other
engines just have a setter as well that just redefines the property
as a data descriptor when called, and returns undefined.
It's bound to the property name and requires an object of the correct
type, so I mirrored these constraints here. Storing the setter and
calling it multiple times will therefore just work.

Implementing this in the wrapper generator is left as an exercise for
the reader, this is going to be used in WindowObject, which isn't
generated from IDL yet.
2021-09-12 15:53:48 +02:00
Linus Groh
c5bd382524 LibJS: Leave NativeFunction's Realm unset if VM has no Interpreter
There's currently a fallback at the call site where the Realm is needed
(due to a slightly incorrect implementation of [[Call]] / [[Construct]])
so this is better than crashing (in LibWeb, currently).
2021-09-12 15:18:25 +02:00
Linus Groh
7b92889e6b LibJS: Change Interpreter::create_with_existing_{global_object => realm}
We need both a GlobalObject and Realm now, but can get the former from
the latter (once initialized).
This also fixes JS execution in LibWeb, as we failed to set the Realm of
the newly created Interpreter in this function.
2021-09-12 15:18:25 +02:00
Linus Groh
106f295916 LibJS+LibWeb: Make JS::Script and Web::HTML::ClassicScript use Realms
The spec wants Script Records to have a Realm, not a GlobalObject.
2021-09-12 15:18:25 +02:00
Timothy Flynn
673fc02ac5 LibJS: Move locale_relevant_extension_keys to Intl.Locale 2021-09-12 12:57:17 +01:00
Timothy Flynn
7769cd2cab LibJS: Move number_format_relevant_extension_keys to Intl.NumberFormat
This method represents the Intl.NumberFormat's [[RelevantExtensionKeys]]
internal slot, so it makes more sense for this to be directly in the
class itself.
2021-09-12 12:57:17 +01:00
Timothy Flynn
94a5a0437c LibJS: Move Intl.NumberFormat's AOs to its object file 2021-09-12 12:57:17 +01:00
Timothy Flynn
0b08201fec LibJS: Move Intl.ListFormat's AOs to its object file
To be consistent with the style in Temporal, let's move all AOs in Intl
to their object file, rather than splitting the AOs between prototype
and constructor files.
2021-09-12 12:57:17 +01:00
Timothy Flynn
ae7b5280c2 LibJS: Make "options" objects const references in NumberFormat's AOs 2021-09-12 12:57:17 +01:00
Timothy Flynn
7f700bd84e LibJS: Make GetNumberOption's "options" object a const reference 2021-09-12 12:57:17 +01:00
Timothy Flynn
aa2af06c84 LibJS: Store Intl.Locale's "tag" argument as a plain string 2021-09-12 12:57:17 +01:00
Timothy Flynn
4411e16798 LibJS: Change GetOption AO to accept the options as a concrete Object
This was being verified at runtime anyways, so let the compiler ensure
it. This also matches the GetOption AO in Temporal now.
2021-09-12 12:57:17 +01:00
Timothy Flynn
ada56981dc LibJS: Sort Intl AbstractOperation declarations by spec ID
The definitions in the .cpp file are already sorted this way.
2021-09-12 12:57:17 +01:00
Timothy Flynn
094c390fb1 LibJS: Move CanonicalCodeForDisplayNames to Intl.DisplayNames
Intl.DisplayNames was the first Intl object implemented, and at that
point all AOs were just put into the main Intl AO header. But AOs that
belong to specific objects belong in that object's header. So this moves
CanonicalCodeForDisplayNames to the Intl.DisplayNames header.
2021-09-12 12:57:17 +01:00
Peter Elliott
6ae1a80583 LibMarkdown: Re-add support for Serenity's style code blocks extension
I decided to not use the text parser for this one and rely on a regex to
parse the style tags. This way it supports only and opening delimiter
run and also is much simpler.
2021-09-12 12:17:16 +02:00
Peter Elliott
565b561522 LibMarkdown: Render sequences of spaces properly in the terminal 2021-09-12 12:17:16 +02:00
Peter Elliott
9c0563cc10 LibMarkdown: Implement hard and soft line breaks
Hard line breaks insert a <br /> when two spaces are at the end of a
line. soft line breaks are just regular newlines, but whitespace is now
stripped before and after them
2021-09-12 12:17:16 +02:00
Peter Elliott
af5a07399e LibMarkdown: Handle delimiter flanking with punctuation
This patch handles the following two rules
1) A delimiter run is either (a) not followed by a Unicode punctuation
   character, or (b) followed by a Unicode punctuation character and
   preceded by Unicode whitespace or a Unicode punctuation character.

2) A _ can be used to open/close a delimiter run if it's (a) not part
   of a left-flanking delimiter run or (b) part of a left-flanking
   delimiter run followed by a Unicode punctuation character.
2021-09-12 12:17:16 +02:00
Peter Elliott
6724d6d391 LibMarkdown: Add terminal rendering for new markdown Text parser 2021-09-12 12:17:16 +02:00
Peter Elliott
ec9f892899 LibMarkdown: Rewrite Inline text parser to be more forgiving
The previous Text::parse was not able to give up on parsing a textual
element, and just leave it as plain text. Because this is a very
important part of markdown, I fully rewrote the parser to support this
without having to backtrack. Also the parser now some other little
features, such ast delimiter runs and flanking.
2021-09-12 12:17:16 +02:00
Linus Groh
80e58dab9a LibJS: Make get_function_realm() actually return a Realm 2021-09-12 11:10:20 +01:00
Linus Groh
06e89311fa LibJS: Set the callee context's realm in prepare_for_ordinary_call()
This includes making FunctionObject::realm() actually return a Realm,
instead of a GlobalObject.
2021-09-12 11:10:20 +01:00
Linus Groh
332946ab4f LibJS: Prepare ExecutionContext to store the current Realm Record
Also add VM::current_realm() to retrieve it, similar to all the other
getters (running_execution_context() et al.).
2021-09-12 11:10:20 +01:00
Linus Groh
15c33477e4 LibJS: Make prepare_for_ordinary_call() new_target parameter an Object*
This got changed in the spec at some point, replacing the assertion in
step 1 with "... and newTarget (an Object or undefined)" in the
parameter description.
Subsequently, there's now one step less, so the numbers all change.
2021-09-12 11:10:20 +01:00
Linus Groh
f29a82dd84 LibJS: Move the GlobalEnvironment from GlobalObject to Realm
This is where the spec wants to have it. Requires a couple of hacks as
currently everything that needs a Realm actually has a GlobalObject, so
we need to go via the Interpreter.
2021-09-12 11:10:20 +01:00
Linus Groh
1e79934acf LibJS: Add [[GlobalThisValue]] internal slot to GlobalEnvironment
Instead of hardcoding the environment's global object as the return
value of GlobalEnvironment::global_this_value(), it now stores an Object
reference which is passed to the constructor for this purpose.

From the spec (https://tc39.es/ecma262/#sec-global-environment-records):

[[GlobalThisValue]] | Object | The value returned by this in global
scope. Hosts may provide any ECMAScript Object value.
2021-09-12 11:10:20 +01:00
Linus Groh
2b8d5696ab LibJS: Allocate a Realm next to GlobalObject in Interpreter::create()
Also pass a Realm reference to the Bytecode::Interpreter constructor,
just like we pass the GlobalObject.
2021-09-12 11:10:20 +01:00
Linus Groh
d9c3bafcd9 LibJS: Start adding a JS::Realm class (spec's "Realm Record") 2021-09-12 11:10:20 +01:00
Liav A
8d0dbdeaac Kernel+Userland: Introduce a new way to reboot and poweroff the machine
This change removes the halt and reboot syscalls, and create a new
mechanism to change the power state of the machine.
Instead of how power state was changed until now, put a SysFS node as
writable only for the superuser, that with a defined value, can result
in either reboot or poweroff.
In the future, a power group can be assigned to this node (which will be
the GroupID responsible for power management).

This opens an opportunity to permit to shutdown/reboot without superuser
permissions, so in the future, a userspace daemon can take control of
this node to perform power management operations without superuser
permissions, if we enforce different UserID/GroupID on that node.
2021-09-12 11:52:16 +02:00
Karol Kosek
f878e4464f LibGfx: Add SystemTheme::load_system_theme(Core::ConfigFile const&)
This makes loading system themes possible via FileSystemAccessClient
(needed for the Theme Editor). :^)
2021-09-12 11:49:52 +02:00
TheFightingCatfish
a81b21c1a7 Kernel+LibC: Implement fsync 2021-09-12 11:24:02 +02:00
Callum Walker
fd3735199b LibCore: Fix link_file inverting src and dst paths on duplicate names
File::link_file takes the dst_path then the src_path so on duplicate
names we tried to create a link at the original file location, which
then flipped the parameters back round again and we ended up with a
broken link from "dst_path (1)" to "src_path (1)".
2021-09-12 04:58:22 +00:00
Andreas Kling
19de6bb1cc LibWeb+Browser: Add Debug menu action for toggling Same-Origin Policy
Sometimes it's useful to turn off the SOP for testing purposes.
Let's make that easy by having a Debug menu item for it. :^)
2021-09-12 02:13:28 +02:00